PSA: llvm::cl now supports subcommands

I submitted this yesterday in r274171. I think this allows for a more intuitive way to structure the options of command line tools. It’s optional and if you do nothing llvm::cl will work as it always has for you.

Probably self explanatory, but here’s some output of --help from llvm-pdbdump, which was updated to use subcommands in r274247, in case anyone wants to see what this looks like.

D:\src\llvmbuild\clang-selfhost>bin\llvm-pdbdump --help
OVERVIEW: LLVM PDB Dumper

USAGE: llvm-pdbdump.exe [subcommand] [options]

SUBCOMMANDS:

pdb2yaml - Generate a detailed YAML description of a PDB File
pretty - Dump semantic information about types and symbols
raw - Dump raw structure of the PDB file
yaml2pdb - Generate a PDB file from a YAML description

Type “llvm-pdbdump.exe -help” to get more help on a specific subcommand

OPTIONS:

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

D:\src\llvmbuild\clang-selfhost>bin\llvm-pdbdump pretty --help
OVERVIEW: LLVM PDB Dumper

SUBCOMMAND ‘pretty’: Dump semantic information about types and symbols

USAGE: llvm-pdbdump.exe pretty [options]

OPTIONS:

Filtering Options:

-exclude-compilands= - Exclude compilands by regular expression
-exclude-symbols= - Exclude symbols by regular expression
-exclude-types= - Exclude types by regular expression
-include-compilands= - Include only compilands those which match a regular expression
-include-symbols= - Include only symbols which match a regular expression
-include-types= - Include only types which match a regular expression
-no-class-definitions - Don’t display full class definitions
-no-compiler-generated - Don’t show compiler generated types and symbols
-no-enum-definitions - Don’t display full enum definitions
-no-system-libs - Don’t show symbols from system libraries

Generic Options:

-help - Display available options (-help-hidden for more)
-help-list - Display list of available options (-help-list-hidden for more)

Other Options:

-load-address= - Assume the module is loaded at the specified address

Symbol Type Options:

-all - Implies all other options in ‘Symbol Types’ category
-compilands - Display compilands
-externals - Dump external symbols
-globals - Dump global symbols
-lines - Line tables
-symbols - Display symbols for each compiland
-types - Display types

D:\src\llvmbuild\clang-selfhost>bin\llvm-pdbdump pdb2yaml --help
OVERVIEW: LLVM PDB Dumper

SUBCOMMAND ‘pdb2yaml’: Generate a detailed YAML description of a PDB File

USAGE: llvm-pdbdump.exe pdb2yaml [options]

OPTIONS:

General options:

-stream-directory - Dump each stream’s block map (implies -stream-metadata)
-stream-metadata - Dump the number of streams and each stream’s size

Generic Options:

-help - Display available options (-help-hidden for more)
-help-list - Display list of available options (-help-list-hidden for more)

Perhaps you could define a default parameter value for the new parameter of
getRegisteredOptions(...) ? That, or the code example given in the comments
should be fixed.
I think a default parameter value = *cl::TopLevelSubCommand would mean that
no code changes are necessary for downstream users (us ;).

cheers,
  Johan

Seems reasonable, I’ll take a look later