[llvm-branch-commits] [libc] [flang] [compiler-rt] [clang] [llvm] [clang-tools-extra] [OptTable] Make new lines in help text respect indentation (PR #74880)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Dec 8 10:47:05 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-support

Author: Andres Villegas (avillega)

<details>
<summary>Changes</summary>

With this changes, new lines in the HelpText defined
in OptTable have the same indentation as the first line.

Before, the help output will look something like:

```
--color=<value>       Whether to use color when
symbolizing log markup: always, auto, never
```

With this change:

```
--color=<value>       - Whether to use color when
                        symbolizing log markup: always, auto, never
```

Note the "-" at the beginning of the help text in the new version,
it was added to clearly separate the HelpText of the different
options.


---
Full diff: https://github.com/llvm/llvm-project/pull/74880.diff


6 Files Affected:

- (modified) llvm/lib/Option/OptTable.cpp (+14-4) 
- (modified) llvm/test/Support/check-default-options.txt (+1-1) 
- (modified) llvm/test/tools/llvm-cvtres/help.test (+9-9) 
- (modified) llvm/test/tools/llvm-rc/helpmsg.test (+15-15) 
- (modified) llvm/test/tools/llvm-readobj/basic.test (+2-2) 
- (modified) llvm/test/tools/llvm-readtapi/command-line.test (+1-1) 


``````````diff
diff --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp
index 50eebf1f954bb..c69365540bed3 100644
--- a/llvm/lib/Option/OptTable.cpp
+++ b/llvm/lib/Option/OptTable.cpp
@@ -662,17 +662,27 @@ static void PrintHelpOptionList(raw_ostream &OS, StringRef Title,
   }
 
   const unsigned InitialPad = 2;
+  constexpr StringLiteral HelpSeparator("- ");
   for (const OptionInfo &Opt : OptionHelp) {
     const std::string &Option = Opt.Name;
-    int Pad = OptionFieldWidth - int(Option.size());
+    int Pad = OptionFieldWidth + InitialPad;
+    int FirstLinePad = OptionFieldWidth - int(Option.size());
     OS.indent(InitialPad) << Option;
 
     // Break on long option names.
-    if (Pad < 0) {
+    if (FirstLinePad < 0) {
       OS << "\n";
-      Pad = OptionFieldWidth + InitialPad;
+      FirstLinePad = OptionFieldWidth + InitialPad;
+      Pad = FirstLinePad;
     }
-    OS.indent(Pad + 1) << Opt.HelpText << '\n';
+
+    SmallVector<StringRef> Lines;
+    Opt.HelpText.split(Lines, '\n');
+    assert(Lines.size() && "Expected at least the first line in the help text");
+    auto *LinesIt = Lines.begin();
+    OS.indent(FirstLinePad + 1) << HelpSeparator << *LinesIt << '\n';
+    while (Lines.end() != ++LinesIt)
+      OS.indent(Pad + 1 + HelpSeparator.size()) << *LinesIt << '\n';
   }
 }
 
diff --git a/llvm/test/Support/check-default-options.txt b/llvm/test/Support/check-default-options.txt
index c71e608429da7..dc9d847a7199a 100644
--- a/llvm/test/Support/check-default-options.txt
+++ b/llvm/test/Support/check-default-options.txt
@@ -2,6 +2,6 @@
 # RUN: llvm-tblgen --help-hidden %t | FileCheck --check-prefix=CHECK-TBLGEN %s
 # RUN: llvm-opt-report --help-hidden %t | FileCheck --check-prefix=CHECK-OPT-RPT %s
 
-# CHECK-READOBJ: -h    Alias for --file-header
+# CHECK-READOBJ: -h  - Alias for --file-header
 # CHECK-TBLGEN:  -h  - Alias for --help
 # CHECK-OPT-RPT: -h  - Alias for --help
diff --git a/llvm/test/tools/llvm-cvtres/help.test b/llvm/test/tools/llvm-cvtres/help.test
index f504e063ac152..3a29d80fcca1c 100644
--- a/llvm/test/tools/llvm-cvtres/help.test
+++ b/llvm/test/tools/llvm-cvtres/help.test
@@ -4,13 +4,13 @@
 ; HELP_TEST: 	  OVERVIEW: Resource Converter
 ; HELP_TEST-DAG:  USAGE: llvm-cvtres [options] file...
 ; HELP_TEST-DAG:  OPTIONS:
-; HELP_TEST-NEXT:   /{{DEFINE}}:symbol Not implemented
-; HELP_TEST-NEXT:   /FOLDDUPS: Not implemented
-; HELP_TEST-NEXT:   /HELP Display available options
+; HELP_TEST-NEXT:   /{{DEFINE}}:symbol - Not implemented
+; HELP_TEST-NEXT:   /FOLDDUPS: - Not implemented
+; HELP_TEST-NEXT:   /HELP - Display available options
 ; HELP_TEST-NEXT:   /MACHINE:{ARM|ARM64|EBC|IA64|X64|X86}
-; HELP_TEST-NEXT:   Machine architecture
-; HELP_TEST-DAG:    /NOLOGO Not implemented
-; HELP_TEST-NEXT:   /OUT:filename Output file
-; HELP_TEST-NEXT:   /READONLY Not implemented
-; HELP_TEST-NEXT:   /TIMESTAMP:<value> Timestamp for coff header, defaults to current time
-; HELP_TEST-NEXT:   /VERBOSE Use verbose output
+; HELP_TEST-NEXT:   - Machine architecture
+; HELP_TEST-DAG:    /NOLOGO - Not implemented
+; HELP_TEST-NEXT:   /OUT:filename - Output file
+; HELP_TEST-NEXT:   /READONLY - Not implemented
+; HELP_TEST-NEXT:   /TIMESTAMP:<value> - Timestamp for coff header, defaults to current time
+; HELP_TEST-NEXT:   /VERBOSE - Use verbose output
diff --git a/llvm/test/tools/llvm-rc/helpmsg.test b/llvm/test/tools/llvm-rc/helpmsg.test
index ecda426e3280a..f312882051dc1 100644
--- a/llvm/test/tools/llvm-rc/helpmsg.test
+++ b/llvm/test/tools/llvm-rc/helpmsg.test
@@ -6,18 +6,18 @@
 ; CHECK:  OVERVIEW: LLVM Resource Converter
 ; CHECK-DAG:  USAGE: llvm-rc [options] file...
 ; CHECK-DAG:  OPTIONS:
-; CHECK-NEXT:    /?          Display this help and exit.
-; CHECK-NEXT:    /C <value>  Set the codepage used for input strings.
-; CHECK-NEXT:    /dry-run    Don't compile the input; only try to parse it.
-; CHECK-NEXT:    /D <value>  Define a symbol for the C preprocessor.
-; CHECK-NEXT:    /FO <value> Change the output file location.
-; CHECK-NEXT:    /H          Display this help and exit.
-; CHECK-NEXT:    /I <value>  Add an include path.
-; CHECK-NEXT:    /LN <value> Set the default language name.
-; CHECK-NEXT:    /L <value>  Set the default language identifier.
-; CHECK-NEXT:    /no-preprocess Don't try to preprocess the input file.
-; CHECK-NEXT:    /N          Null-terminate all strings in the string table.
-; CHECK-NEXT:    /U <value>  Undefine a symbol for the C preprocessor.
-; CHECK-NEXT:    /V          Be verbose.
-; CHECK-NEXT:    /X          Ignore 'include' variable.
-; CHECK-NEXT:    /Y          Suppress warnings on duplicate resource IDs.
+; CHECK-NEXT:    /?             - Display this help and exit.
+; CHECK-NEXT:    /C <value>     - Set the codepage used for input strings.
+; CHECK-NEXT:    /dry-run       - Don't compile the input; only try to parse it.
+; CHECK-NEXT:    /D <value>     - Define a symbol for the C preprocessor.
+; CHECK-NEXT:    /FO <value>    - Change the output file location.
+; CHECK-NEXT:    /H             - Display this help and exit.
+; CHECK-NEXT:    /I <value>     - Add an include path.
+; CHECK-NEXT:    /LN <value>    - Set the default language name.
+; CHECK-NEXT:    /L <value>     - Set the default language identifier.
+; CHECK-NEXT:    /no-preprocess - Don't try to preprocess the input file.
+; CHECK-NEXT:    /N             - Null-terminate all strings in the string table.
+; CHECK-NEXT:    /U <value>     - Undefine a symbol for the C preprocessor.
+; CHECK-NEXT:    /V             - Be verbose.
+; CHECK-NEXT:    /X             - Ignore 'include' variable.
+; CHECK-NEXT:    /Y             - Suppress warnings on duplicate resource IDs.
diff --git a/llvm/test/tools/llvm-readobj/basic.test b/llvm/test/tools/llvm-readobj/basic.test
index 73912373d7d2f..8887f0641435c 100644
--- a/llvm/test/tools/llvm-readobj/basic.test
+++ b/llvm/test/tools/llvm-readobj/basic.test
@@ -54,8 +54,8 @@ HELP: OVERVIEW: LLVM Object Reader
 OBJ: llvm-readobj{{.*}} [options] <input object files>
 ELF: llvm-readelf{{.*}} [options] <input object files>
 HELP: OPTIONS:
-HELP: -s   Alias for --symbols
-HELP: -t   Alias for --section-details
+HELP: -s   - Alias for --symbols
+HELP: -t   - Alias for --section-details
 HELP: OPTIONS (ELF specific):
 HELP: --dynamic-table
 HELP: OPTIONS (Mach-O specific):
diff --git a/llvm/test/tools/llvm-readtapi/command-line.test b/llvm/test/tools/llvm-readtapi/command-line.test
index 1006bfe9cc253..e8881348253c4 100644
--- a/llvm/test/tools/llvm-readtapi/command-line.test
+++ b/llvm/test/tools/llvm-readtapi/command-line.test
@@ -8,7 +8,7 @@
 CHECK: OVERVIEW: LLVM TAPI file reader and manipulator
 CHECK: USAGE: llvm-readtapi [options] [-arch <arch>]* <inputs> [-o <output>]*
 CHECK: OPTIONS:
-CHECK:   -help    display this help
+CHECK:   -help    - display this help
 
 MULTI_ACTION: error: only one of the following actions can be specified: -merge -compare
 FILE_FORMAT: error: deprecated filetype 'tbd-v2' is not supported to write

``````````

</details>


https://github.com/llvm/llvm-project/pull/74880


More information about the llvm-branch-commits mailing list