This is an archive of the discontinued LLVM Phabricator instance.

[CommandLine] Change help output to prefix long options with `--` instead of `-`. NFC . Part 3 of 5
ClosedPublic

Authored by hintonda on Apr 29 2019, 10:28 AM.

Event Timeline

hintonda created this revision.Apr 29 2019, 10:28 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 29 2019, 10:28 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
hintonda retitled this revision from [CommandLine] Change help output to prefix long options with `--` instead of `-`. NFC to [CommandLine] Change help output to prefix long options with `--` instead of `-`. NFC . Part 3 of 5.Apr 29 2019, 10:41 AM
hintonda updated this revision to Diff 197232.Apr 29 2019, 5:37 PM
  • Fix dashes for help on error.
hintonda updated this revision to Diff 197267.Apr 30 2019, 1:26 AM
  • Fix dashes in error messages and in tests.
Herald added a project: Restricted Project. · View Herald TranscriptApr 30 2019, 1:26 AM
thopre added inline comments.Apr 30 2019, 1:59 AM
llvm/lib/Support/CommandLine.cpp
95

Any reason why not take a StringRef of the option to compute the prefix of? That would put the .size() gymnastic in one place instead of many.

101

Likewise.

hintonda marked an inline comment as done.Apr 30 2019, 2:30 AM
hintonda added inline comments.
llvm/lib/Support/CommandLine.cpp
95

Actually, that's what I originally had, but since it was only a few places, I changed it to take the length. Now that I see it's used all over, I'll probably switch it back as you suggest.

hintonda updated this revision to Diff 197466.Apr 30 2019, 3:42 PM
  • Refactor and fix additional dashes in error messages and tests.
thopre accepted this revision.May 2 2019, 1:52 AM

That's much better thank you. I like the stream shift operator overload, nice touch. LGTM but give it a day for other to give feedback.

This revision is now accepted and ready to land.May 2 2019, 1:52 AM
This revision was automatically updated to reflect the committed changes.
thakis added a subscriber: thakis.May 3 2019, 10:59 AM

I happened to see this go by. Is there an explanation of the overall goal somewhere? In general, requiring -- for long flags sounds like a great change to me, but there are a few exceptions: For example. lld-link should keep accepting long flags with a single dash for link.exe compatibility.

I happened to see this go by. Is there an explanation of the overall goal somewhere? In general, requiring -- for long flags sounds like a great change to me, but there are a few exceptions: For example. lld-link should keep accepting long flags with a single dash for link.exe compatibility.

The 5th and final patch, D61294, "[CommandLine] Add long option flag for cl::ParseCommandLineOptions . Part 5 of 5", adds a flag that requires long options use the --. It's an opt-in strategy, so only tools that want the GNU getopt_long behavior would want to set it. Otherwise, everything works the way it does currently, with the exception of help printing -- for long options.

As noted in D61294, these changes were motivated by this discussion: http://lists.llvm.org/pipermail/llvm-dev/2019-April/131786.html

Of course, this doesn't change tblgen generated options which are a different animal.

Thanks for the context. Sounds great :)