[llvm] r372088 - [llvm-ar] Parse 'h' and '-h': display help and exit

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 17 02:25:52 PDT 2019


Author: maskray
Date: Tue Sep 17 02:25:52 2019
New Revision: 372088

URL: http://llvm.org/viewvc/llvm-project?rev=372088&view=rev
Log:
[llvm-ar] Parse 'h' and '-h': display help and exit

Support `llvm-ar h` and `llvm-ar -h` because they may be what users try
at first. Note, operation 'h' is undocumented in GNU ar.

Reviewed By: jhenderson

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

Added:
    llvm/trunk/test/tools/llvm-ar/help-message.test
Modified:
    llvm/trunk/tools/llvm-ar/llvm-ar.cpp

Added: llvm/trunk/test/tools/llvm-ar/help-message.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-ar/help-message.test?rev=372088&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-ar/help-message.test (added)
+++ llvm/trunk/test/tools/llvm-ar/help-message.test Tue Sep 17 02:25:52 2019
@@ -0,0 +1,6 @@
+# RUN: llvm-ar h | FileCheck %s
+# RUN: llvm-ar -h | FileCheck %s
+# RUN: llvm-ar -help | FileCheck %s
+# RUN: llvm-ar --help | FileCheck %s
+
+# CHECK: USAGE: llvm-ar

Modified: llvm/trunk/tools/llvm-ar/llvm-ar.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ar/llvm-ar.cpp?rev=372088&r1=372087&r2=372088&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-ar/llvm-ar.cpp (original)
+++ llvm/trunk/tools/llvm-ar/llvm-ar.cpp Tue Sep 17 02:25:52 2019
@@ -70,14 +70,14 @@ USAGE: llvm-ar [options] [-]<operation>[
        llvm-ar -M [<mri-script]
 
 OPTIONS:
-  --format              - Archive format to create
+  --format              - archive format to create
     =default            -   default
     =gnu                -   gnu
     =darwin             -   darwin
     =bsd                -   bsd
-  --plugin=<string>     - Ignored for compatibility
-  --help                - Display available options
-  --version             - Display the version of this program
+  --plugin=<string>     - ignored for compatibility
+  -h --help             - display this help and exit
+  --version             - print the version and exit
   @<file>               - read options from <file>
 
 OPERATIONS:
@@ -1030,7 +1030,7 @@ static void runMRIScript() {
 }
 
 static bool handleGenericOption(StringRef arg) {
-  if (arg == "-help" || arg == "--help") {
+  if (arg == "h" || arg.startswith("-h") || arg == "--help") {
     printHelpMessage();
     return true;
   }




More information about the llvm-commits mailing list