[PATCH] D122654: [doc] Improve clang auto-generated help
serge via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 29 06:35:16 PDT 2022
serge-sans-paille created this revision.
serge-sans-paille added a reviewer: aaron.ballman.
Herald added a subscriber: hiraditya.
Herald added a project: All.
serge-sans-paille requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
If no MetaVar is provided and an enumeration of values is set, document it in
the same way Python argparse does. Also add a proper unittest for help strings
This is a follow-up to 6d7317894f89cea29a2ecf7d86ac88adc40a5eaa
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D122654
Files:
llvm/include/llvm/Option/OptTable.h
llvm/lib/Option/OptTable.cpp
llvm/unittests/Option/OptionParsingTest.cpp
llvm/unittests/Option/Opts.td
Index: llvm/unittests/Option/Opts.td
===================================================================
--- llvm/unittests/Option/Opts.td
+++ 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=">;
Index: llvm/unittests/Option/OptionParsingTest.cpp
===================================================================
--- llvm/unittests/Option/OptionParsingTest.cpp
+++ 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!");
Index: llvm/lib/Option/OptTable.cpp
===================================================================
--- llvm/lib/Option/OptTable.cpp
+++ 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 += "<value>";
break;
}
Index: llvm/include/llvm/Option/OptTable.h
===================================================================
--- llvm/include/llvm/Option/OptTable.h
+++ 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; }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122654.418859.patch
Type: text/x-patch
Size: 3396 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220329/f4ba68c9/attachment.bin>
More information about the llvm-commits
mailing list