This is an archive of the discontinued LLVM Phabricator instance.

[CommandLine] Allow Options to specify multiple OptionCategory's.
ClosedPublic

Authored by hintonda on May 5 2019, 2:05 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

hintonda created this revision.May 5 2019, 2:05 PM
Herald added a project: Restricted Project. ยท View Herald TranscriptMay 5 2019, 2:05 PM
Herald added a subscriber: hiraditya. ยท View Herald Transcript

May I ask you to share some dumps of some-command -help (a demo how you'll make use of the multiple categories)๐Ÿ˜

llvm/lib/Support/CommandLine.cpp
429 โ†—(On Diff #198201)

Can you explain why Categories cannot be empty? Is it because an option has one category when it is registered? (Sorry as I'm not very familiar with the code)

llvm/unittests/Support/CommandLineTest.cpp
99 โ†—(On Diff #198201)

Since the file includes STLExtras.h you may use the range-style llvm::find_if to simplify begin/end.

hintonda marked 2 inline comments as done.May 5 2019, 9:17 PM

May I ask you to share some dumps of some-command -help (a demo how you'll make use of the multiple categories)๐Ÿ˜

Sure, I work up an example. Btw, my ultimate plan is to add categories to the passes so that bugpoint help isn't just a huge mess. That's the motivation for this change. When I started adding them, I found it wasn't really doable without this change since so many passes shared options.

llvm/lib/Support/CommandLine.cpp
429 โ†—(On Diff #198201)

The ctor for Option adds GeneralCategory. The old way just replaced it if the user provided their own. With this change, it's the first one on the vector. That's why I check index 0.

llvm/unittests/Support/CommandLineTest.cpp
99 โ†—(On Diff #198201)

Ah, okay. Will do, thanks...

MaskRay added inline comments.May 5 2019, 9:29 PM
llvm/lib/Support/CommandLine.cpp
2421 โ†—(On Diff #198201)

Use llvm::find (or llvm::count) and delete the otherwise unused CategoriesBegin CategoriesEnd.

hintonda marked an inline comment as done.May 5 2019, 9:34 PM
hintonda added inline comments.
llvm/lib/Support/CommandLine.cpp
2421 โ†—(On Diff #198201)

I'll update them all. Thanks for point that out.

May I ask you to share some dumps of some-command -help (a demo how you'll make use of the multiple categories)๐Ÿ˜

Sure, I work up an example. Btw, my ultimate plan is to add categories to the passes so that bugpoint help isn't just a huge mess. That's the motivation for this change. When I started adding them, I found it wasn't really doable without this change since so many passes shared options.

There's currently not clean way to do this without being able to capture stdout when calling ParseCommandLineOptions, so I'll add that in a separate patch for that and use it here. Please see D30893 for something similar that was done to capture stderr.

May I ask you to share some dumps of some-command -help (a demo how you'll make use of the multiple categories)๐Ÿ˜

Sure, I work up an example. Btw, my ultimate plan is to add categories to the passes so that bugpoint help isn't just a huge mess. That's the motivation for this change. When I started adding them, I found it wasn't really doable without this change since so many passes shared options.

There's currently not clean way to do this without being able to capture stdout when calling ParseCommandLineOptions, so I'll add that in a separate patch for that and use it here. Please see D30893 for something similar that was done to capture stderr.

After looking into it, I'm not going to try to capture stdout. So, I'm not going to add a test that compares help output. This is consistent with the status quo -- there isn't a test for that in llvm. I suppose I could add one to clang since I'd have access to %clang in lit, but adding an llvm test to clang seems a bit odd.

May I ask you to share some dumps of some-command -help (a demo how you'll make use of the multiple categories)๐Ÿ˜

Here's a dump of the test I was attempting to add with the following options:

cl::OptionCategory Cat1("Category One", "  Category One description");
cl::OptionCategory Cat2("Category Two", "  Category Two description");
cl::opt<bool> GeneralOpt("general-option");
cl::opt<bool> Cat1Opt("category1-option", cl::cat(Cat1));
cl::opt<bool> Cat2Opt("category2-option", cl::cat(Cat2));
cl::opt<bool> Cat1AndCat2Opt("category1-and-category2-option", cl::cat(Cat1), cl::cat(Cat2));
USAGE: prog [options]

OPTIONS:

Category One:
  Category One description

  --category1-and-category2-option    -
  --category1-option                  -

Category Two:
  Category Two description

  --category1-and-category2-option    -
  --category2-option                  -

Color Options:

  --color                             - Use colors in output (default=autodetect)

General options:

  --env-test-opt=<string>             -
  --general-option                    -
  --program-test-string-arg1=<string> -
  --program-test-string-arg2=<string> -
  --time-trace-granularity=<uint>     - Minimum time granularity (in microseconds) traced by time profiler

Generic Options:

  --help                              - Display available options (--help-hidden for more)
  --help-list                         - Display list of available options (--help-list-hidden for more)
  --version                           - Display the version of this program
hintonda updated this revision to Diff 198351.May 6 2019, 3:10 PM
  • Address comments
MaskRay accepted this revision.May 6 2019, 9:49 PM
This revision is now accepted and ready to land.May 6 2019, 9:49 PM
This revision was automatically updated to reflect the committed changes.