[Lldb-commits] [lldb] 091e760 - [lldb] Don't print "Command Options Usage:" for an alias with no options

David Spickett via lldb-commits lldb-commits at lists.llvm.org
Wed Jan 12 02:07:43 PST 2022


Author: David Spickett
Date: 2022-01-12T10:07:38Z
New Revision: 091e760cd39848f3c41900b5104b3d92028d91b4

URL: https://github.com/llvm/llvm-project/commit/091e760cd39848f3c41900b5104b3d92028d91b4
DIFF: https://github.com/llvm/llvm-project/commit/091e760cd39848f3c41900b5104b3d92028d91b4.diff

LOG: [lldb] Don't print "Command Options Usage:" for an alias with no options

"shell" is an alias to "platform shell -h --". Previously you would get this
help text:

(lldb) help shell
Run a shell command on the host.  Expects 'raw' input (see 'help raw-input'.)

Syntax: shell <shell-command>

Command Options Usage:

'shell' is an abbreviation for 'platform shell -h   --'

Since the code doesn't handle the base command having options
but the alias removing them. With these changes you get:

(lldb) help shell
Run a shell command on the host.  Expects 'raw' input (see 'help raw-input'.)

Syntax: shell <shell-command>

'shell' is an abbreviation for 'platform shell -h   --'

Note that we already handle a non-alias command having no options,
for example "quit":

(lldb) help quit
Quit the LLDB debugger.

Syntax: quit [exit-code]

Reviewed By: JDevlieghere, jingham

Differential Revision: https://reviews.llvm.org/D117004

Added: 
    

Modified: 
    lldb/source/Interpreter/Options.cpp
    lldb/test/API/commands/platform/basic/TestPlatformCommand.py

Removed: 
    


################################################################################
diff  --git a/lldb/source/Interpreter/Options.cpp b/lldb/source/Interpreter/Options.cpp
index 4aa298f0382b1..feebe338bc9aa 100644
--- a/lldb/source/Interpreter/Options.cpp
+++ b/lldb/source/Interpreter/Options.cpp
@@ -403,7 +403,12 @@ void Options::GenerateOptionUsage(Stream &strm, CommandObject *cmd,
   } else
     name = "";
 
-  strm.PutCString("\nCommand Options Usage:\n");
+  const uint32_t num_options = NumCommandOptions();
+  if (num_options == 0)
+    return;
+
+  if (!only_print_args)
+    strm.PutCString("\nCommand Options Usage:\n");
 
   strm.IndentMore(2);
 
@@ -413,10 +418,6 @@ void Options::GenerateOptionUsage(Stream &strm, CommandObject *cmd,
   //                                                   [options-for-level-1]
   //                                                   etc.
 
-  const uint32_t num_options = NumCommandOptions();
-  if (num_options == 0)
-    return;
-
   uint32_t num_option_sets = GetRequiredOptions().size();
 
   uint32_t i;
@@ -531,9 +532,9 @@ void Options::GenerateOptionUsage(Stream &strm, CommandObject *cmd,
     strm << " " << arguments_str.GetString();
   }
 
-  strm.Printf("\n\n");
-
   if (!only_print_args) {
+    strm.Printf("\n\n");
+
     // Now print out all the detailed information about the various options:
     // long form, short form and help text:
     //   -short <argument> ( --long_name <argument> )

diff  --git a/lldb/test/API/commands/platform/basic/TestPlatformCommand.py b/lldb/test/API/commands/platform/basic/TestPlatformCommand.py
index dc1701258246a..1c981e4bddd92 100644
--- a/lldb/test/API/commands/platform/basic/TestPlatformCommand.py
+++ b/lldb/test/API/commands/platform/basic/TestPlatformCommand.py
@@ -20,10 +20,12 @@ def test_help_platform(self):
         self.runCmd("help platform")
 
     @no_debug_info_test
-    def test_help_platform(self):
+    def test_help_shell_alias(self):
         self.expect("help shell", substrs=["Run a shell command on the host.",
-                                           "shell <shell-command>"])
-
+                                           "shell <shell-command>",
+                                           "'shell' is an abbreviation"])
+        # "platform shell" has options. The "shell" alias for it does not.
+        self.expect("help shell", substrs=["Command Options:"], matching=False)
 
     @no_debug_info_test
     def test_list(self):


        


More information about the lldb-commits mailing list