[PATCH] Putting all the standard tool options into a "Generic" category.

Duncan P. N. Exon Smith dexonsmith at apple.com
Fri Jan 23 17:06:46 PST 2015


LGTM.

> On 2015-Jan-23, at 16:53, Chris Bieneman <beanz at apple.com> wrote:
> 
> Updated the test case for HideUnrelatedOptions API to validate that "generic" options are not hidden.
> 
> 
> http://reviews.llvm.org/D7150
> 
> Files:
>  lib/Support/CommandLine.cpp
>  unittests/Support/CommandLineTest.cpp
> 
> Index: lib/Support/CommandLine.cpp
> ===================================================================
> --- lib/Support/CommandLine.cpp
> +++ lib/Support/CommandLine.cpp
> @@ -1653,39 +1653,45 @@
> static HelpPrinterWrapper WrappedHiddenPrinter(UncategorizedHiddenPrinter,
>                                                CategorizedHiddenPrinter);
> 
> +// Define a category for generic options that all tools should have.
> +static cl::OptionCategory GenericCategory("Generic Options");
> +
> // Define uncategorized help printers.
> // -help-list is hidden by default because if Option categories are being used
> // then -help behaves the same as -help-list.
> static cl::opt<HelpPrinter, true, parser<bool>> HLOp(
>     "help-list",
>     cl::desc("Display list of available options (-help-list-hidden for more)"),
> -    cl::location(UncategorizedNormalPrinter), cl::Hidden, cl::ValueDisallowed);
> +    cl::location(UncategorizedNormalPrinter), cl::Hidden, cl::ValueDisallowed,
> +    cl::cat(GenericCategory));
> 
> static cl::opt<HelpPrinter, true, parser<bool>>
>     HLHOp("help-list-hidden", cl::desc("Display list of all available options"),
>           cl::location(UncategorizedHiddenPrinter), cl::Hidden,
> -          cl::ValueDisallowed);
> +          cl::ValueDisallowed, cl::cat(GenericCategory));
> 
> // Define uncategorized/categorized help printers. These printers change their
> // behaviour at runtime depending on whether one or more Option categories have
> // been declared.
> static cl::opt<HelpPrinterWrapper, true, parser<bool>>
>     HOp("help", cl::desc("Display available options (-help-hidden for more)"),
> -        cl::location(WrappedNormalPrinter), cl::ValueDisallowed);
> +        cl::location(WrappedNormalPrinter), cl::ValueDisallowed,
> +        cl::cat(GenericCategory));
> 
> static cl::opt<HelpPrinterWrapper, true, parser<bool>>
>     HHOp("help-hidden", cl::desc("Display all available options"),
> -         cl::location(WrappedHiddenPrinter), cl::Hidden, cl::ValueDisallowed);
> +         cl::location(WrappedHiddenPrinter), cl::Hidden, cl::ValueDisallowed,
> +         cl::cat(GenericCategory));
> 
> static cl::opt<bool> PrintOptions(
>     "print-options",
>     cl::desc("Print non-default options after command line parsing"),
> -    cl::Hidden, cl::init(false));
> +    cl::Hidden, cl::init(false), cl::cat(GenericCategory));
> 
> static cl::opt<bool> PrintAllOptions(
>     "print-all-options",
>     cl::desc("Print all option values after command line parsing"), cl::Hidden,
> -    cl::init(false));
> +    cl::init(false), cl::cat(GenericCategory));
> 
> void HelpPrinterWrapper::operator=(bool Value) {
>   if (Value == false)
> @@ -1790,7 +1796,8 @@
> 
> static cl::opt<VersionPrinter, true, parser<bool>>
>     VersOp("version", cl::desc("Display the version of this program"),
> -           cl::location(VersionPrinterInstance), cl::ValueDisallowed);
> +           cl::location(VersionPrinterInstance), cl::ValueDisallowed,
> +           cl::cat(GenericCategory));
> 
> // Utility function for printing the help message.
> void cl::PrintHelpMessage(bool Hidden, bool Categorized) {
> @@ -1836,8 +1843,8 @@
>   StringMap<cl::Option *> Options;
>   cl::getRegisteredOptions(Options);
>   for (auto &I : Options) {
> -    if (I.second->Category != &Category && I.first() != "help" &&
> -        I.first() != "version")
> +    if (I.second->Category != &Category &&
> +        I.second->Category != &GenericCategory)
>       I.second->setHiddenFlag(cl::ReallyHidden);
>   }
> }
> Index: unittests/Support/CommandLineTest.cpp
> ===================================================================
> --- unittests/Support/CommandLineTest.cpp
> +++ unittests/Support/CommandLineTest.cpp
> @@ -240,6 +240,11 @@
>       << "Failed to hide extra option.";
>   ASSERT_EQ(cl::NotHidden, TestOption2.getOptionHiddenFlag())
>       << "Hid extra option that should be visable.";
> +
> +  StringMap<cl::Option*> Map;
> +  cl::getRegisteredOptions(Map);
> +  ASSERT_EQ(cl::NotHidden, Map["help"]->getOptionHiddenFlag())
> +      << "Hid default option that should be visable.";
> }
> 
> }  // anonymous namespace
> 
> EMAIL PREFERENCES
>  http://reviews.llvm.org/settings/panel/emailpreferences/
> <D7150.18700.patch>





More information about the llvm-commits mailing list