<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Thu, Sep 15, 2016 at 12:45 AM David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg"><div class="gmail_quote gmail_msg"><div dir="ltr" class="gmail_msg">On Tue, Sep 13, 2016 at 6:37 PM Dean Michael Berris <<a href="mailto:dberris@google.com" class="gmail_msg" target="_blank">dberris@google.com</a>> wrote:<br class="gmail_msg"></div><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg"><div class="gmail_quote gmail_msg"><div dir="ltr" class="gmail_msg">On Wed, Sep 14, 2016 at 3:13 AM David Blaikie <<a href="mailto:dblaikie@gmail.com" class="gmail_msg" target="_blank">dblaikie@gmail.com</a>> wrote:<br class="gmail_msg"></div><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg"><div class="gmail_quote gmail_msg"><div dir="ltr" class="gmail_msg">On Mon, Sep 12, 2016 at 6:57 PM Dean Michael Berris <<a href="mailto:dberris@google.com" class="gmail_msg" target="_blank">dberris@google.com</a>> wrote:<br class="gmail_msg"></div><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">dberris created this revision.<br class="gmail_msg">
dberris added reviewers: zturner, dblaikie, echristo.<br class="gmail_msg">
dberris added a subscriber: llvm-commits.<br class="gmail_msg">
Herald added a subscriber: mehdi_amini.<br class="gmail_msg">
<br class="gmail_msg">
This should allow users of the library to get a range to iterate through<br class="gmail_msg">
all the subcommands that are registered to the global parser. This<br class="gmail_msg">
allows users to define subcommands in libraries that self-register to<br class="gmail_msg">
have dispatch done at a different stage (like main). It allows for<br class="gmail_msg">
writing code like the following:<br class="gmail_msg">
<br class="gmail_msg">
    for (auto *S : cl::getRegisteredSubcommands()) {<br class="gmail_msg">
      if (*S) {<br class="gmail_msg">
        // Dispatch on S->getName().<br class="gmail_msg">
      }<br class="gmail_msg">
    }<br class="gmail_msg"></blockquote></div></div><div dir="ltr" class="gmail_msg"><div class="gmail_quote gmail_msg"><div class="gmail_msg"><br class="gmail_msg">FWIW: I wasn't expecting/suggesting we should have to compare by strings (stringly typed isn't ideal, of course) - I was hoping/figuring we could declaer the subcommand in the header (along with the single entry point function) and then define it over in the file that defines the single entry point along with the subcommand's flags.<br class="gmail_msg"></div></div></div></blockquote><div class="gmail_msg"><br class="gmail_msg"></div></div></div><div dir="ltr" class="gmail_msg"><div class="gmail_quote gmail_msg"><div class="gmail_msg">Unfortunately that doesn't remove the dispatch, which would be manual, as opposed to doing this which would be automatic -- i.e. all the implementations can register a function to invoke to a global map, which is used to dispatch, makes extending easier/simpler than having to manually add if statements.</div></div></div></blockquote></div></div><div dir="ltr" class="gmail_msg"><div class="gmail_quote gmail_msg"><div class="gmail_msg"><br class="gmail_msg">Ah, OK - that's more fuss/bother than I was thinking of for a handful of things - a switch/if chain in main that was pretty mechanical/repetitive didn't seem like a big burden, but I don't mind a registration system if you prefer that (it trips into my "potentially overengineering" bucket - so if you want to save some time/work, don't feel like I'm pushing you to build such a registration system).<br class="gmail_msg"><br class="gmail_msg"></div></div></div></blockquote><div><br></div><div>It's actually less work, given that the number of patches I have lined up already make this cumbersome to do (3 might be fine, but 5 isn't, and certainly not if we're going to implement more).</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg"><div class="gmail_quote gmail_msg"><div class="gmail_msg">(but mostly it was the suggested string comparison that I was extra uncomfortable with here - so long as the registration system used the Subcommand + dispatch function, rather than the name + dispatch function, I'd be more or less comfortable with it)<br class="gmail_msg"></div></div></div></blockquote><div><br></div><div>Yes, the description gives the idea. :) You can certainly use the subcommand's pointer as the identifier in the registry instead, but that's just one of the many ways to do it.</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg"><div class="gmail_quote gmail_msg"><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></div></blockquote></div></div>