summaryrefslogtreecommitdiffstats
path: root/llvm/include
diff options
context:
space:
mode:
authorDean Michael Berris <dberris@google.com>2016-10-05 05:20:08 +0000
committerDean Michael Berris <dberris@google.com>2016-10-05 05:20:08 +0000
commit27358cff88f929cee961d96e03706083d12ae7c7 (patch)
tree0374253222ebe9e0f0a493f25477d75451459b1c /llvm/include
parent3fce2fdf4c660df108cf506ca7d308c795842243 (diff)
downloadbcm5719-llvm-27358cff88f929cee961d96e03706083d12ae7c7.tar.gz
bcm5719-llvm-27358cff88f929cee961d96e03706083d12ae7c7.zip
[Support][CommandLine] Add cl::getRegisteredSubcommands()
This should allow users of the library to get a range to iterate through all the subcommands that are registered to the global parser. This allows users to define subcommands in libraries that self-register to have dispatch done at a different stage (like main). It allows for writing code like the following: for (auto *S : cl::getRegisteredSubcommands()) { if (*S) { // Dispatch on S->getName(). } } This change also contains tests that show this usage pattern. Reviewers: zturner, dblaikie, echristo Subscribers: llvm-commits, mehdi_amini Differential Revision: https://reviews.llvm.org/D24489 llvm-svn: 283296
Diffstat (limited to 'llvm/include')
-rw-r--r--llvm/include/llvm/Support/CommandLine.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/llvm/include/llvm/Support/CommandLine.h b/llvm/include/llvm/Support/CommandLine.h
index f2e8b281716..c46a99cb6bd 100644
--- a/llvm/include/llvm/Support/CommandLine.h
+++ b/llvm/include/llvm/Support/CommandLine.h
@@ -1736,6 +1736,28 @@ void PrintHelpMessage(bool Hidden = false, bool Categorized = false);
/// than just handing around a global list.
StringMap<Option *> &getRegisteredOptions(SubCommand &Sub = *TopLevelSubCommand);
+/// \brief Use this to get all registered SubCommands from the provided parser.
+///
+/// \return A range of all SubCommand pointers registered with the parser.
+///
+/// Typical usage:
+/// \code
+/// main(int argc, char* argv[]) {
+/// llvm::cl::ParseCommandLineOptions(argc, argv);
+/// for (auto* S : llvm::cl::getRegisteredSubcommands()) {
+/// if (*S) {
+/// std::cout << "Executing subcommand: " << S->getName() << std::endl;
+/// // Execute some function based on the name...
+/// }
+/// }
+/// }
+/// \endcode
+///
+/// This interface is useful for defining subcommands in libraries and
+/// the dispatch from a single point (like in the main function).
+iterator_range<typename SmallPtrSet<SubCommand *, 4>::iterator>
+getRegisteredSubcommands();
+
//===----------------------------------------------------------------------===//
// Standalone command line processing utilities.
//
OpenPOWER on IntegriCloud