diff --git a/llvm/include/llvm/Option/OptTable.h b/llvm/include/llvm/Option/OptTable.h --- a/llvm/include/llvm/Option/OptTable.h +++ b/llvm/include/llvm/Option/OptTable.h @@ -127,6 +127,11 @@ return getInfo(id).MetaVar; } + /// Get the values this option can take. + const char *getOptionValues(OptSpecifier id) const { + return getInfo(id).Values; + } + /// Specify the environment variable where initial options should be read. void setInitialOptionsFromEnvironment(const char *E) { EnvVar = E; } diff --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp --- a/llvm/lib/Option/OptTable.cpp +++ b/llvm/lib/Option/OptTable.cpp @@ -570,7 +570,11 @@ case Option::JoinedAndSeparateClass: if (const char *MetaVarName = Opts.getOptionMetaVar(Id)) Name += MetaVarName; - else + else if (const char *Values = Opts.getOptionValues(Id)) { + Name += "{"; + Name += Values; + Name += "}"; + } else Name += ""; break; } diff --git a/llvm/unittests/Option/OptionParsingTest.cpp b/llvm/unittests/Option/OptionParsingTest.cpp --- a/llvm/unittests/Option/OptionParsingTest.cpp +++ b/llvm/unittests/Option/OptionParsingTest.cpp @@ -94,7 +94,27 @@ std::string Help; raw_string_ostream RSO(Help); T.printHelp(RSO, "test", "title!"); - EXPECT_NE(std::string::npos, Help.find("-A")); + std::string RefHelp = "OVERVIEW: title!\n" + "\n" + "USAGE: test\n" + "\n" + "OPTIONS:\n" + " -A The A option\n" + " --blarn The blarn option\n" + " -blorp The blorp option\n" + " -BB The B option\n" + " /cramb:CRAMB The cramb option\n" + " -C C The C option\n" + " /C C The C option\n" + " -doopf1 The doopf1 option\n" + " -doopf2 The doopf2 option\n" + " -DD The D option\n" + " --ermghERMGH The ermgh option\n" + " --fjormp The fjormp option\n" + " -F F The F option\n" + " -GG The G option\n" + " --with-values={1,2,3} A valuable option\n"; + EXPECT_EQ(Help, RefHelp); // Check usage line. T.printHelp(RSO, "name [options] file...", "title!"); diff --git a/llvm/unittests/Option/Opts.td b/llvm/unittests/Option/Opts.td --- a/llvm/unittests/Option/Opts.td +++ b/llvm/unittests/Option/Opts.td @@ -37,6 +37,7 @@ def Doopf2 : Flag<["-"], "doopf2">, HelpText<"The doopf2 option">, Flags<[OptFlag2]>; def Ermgh : Joined<["--"], "ermgh">, HelpText<"The ermgh option">, MetaVarName<"ERMGH">, Flags<[OptFlag1]>; def Fjormp : Flag<["--"], "fjormp">, HelpText<"The fjormp option">, Flags<[OptFlag1]>; +def WithValues : Joined<["--"], "with-values=">, HelpText<"A valuable option">, Flags<[OptFlag1]>, Values<"1,2,3">; def Glorrmp_eq : Flag<["--"], "glorrmp=">;