[llvm] [readtapi] Cleanup printing command line options (PR #75106)

Cyndy Ishida via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 11 13:40:19 PST 2023


https://github.com/cyndyishida created https://github.com/llvm/llvm-project/pull/75106

 Also, add a version option.

>From c14617541cf693324e6cb30b1171828702e1abc2 Mon Sep 17 00:00:00 2001
From: Cyndy Ishida <cyndy_ishida at apple.com>
Date: Mon, 11 Dec 2023 13:02:34 -0800
Subject: [PATCH] [readtapi] Cleanup printing command line options

 Also add -version option.
---
 llvm/test/tools/llvm-readtapi/command-line.test | 17 +++++++++++------
 llvm/tools/llvm-readtapi/TapiOpts.td            | 10 ++++++----
 llvm/tools/llvm-readtapi/llvm-readtapi.cpp      |  8 +++++++-
 3 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/llvm/test/tools/llvm-readtapi/command-line.test b/llvm/test/tools/llvm-readtapi/command-line.test
index 1006bfe9cc2537..856e94d130d822 100644
--- a/llvm/test/tools/llvm-readtapi/command-line.test
+++ b/llvm/test/tools/llvm-readtapi/command-line.test
@@ -4,12 +4,17 @@
 ; RUN: not llvm-readtapi -merge -compare -compact %t/tmp.tbd %t/tmp2.tbd 2>&1 | FileCheck %s --check-prefix MULTI_ACTION
 // Check unsupported file output format.
 ; RUN: not llvm-readtapi -merge -compact %t/tmp.tbd %t/tmp2.tbd --filetype=tbd-v2 2>&1 | FileCheck %s --check-prefix FILE_FORMAT 
+// Check version printing.
+; RUN: llvm-readtapi -v 2>&1 | FileCheck %s --check-prefix VERSION
+; RUN: llvm-readtapi --version 2>&1 | FileCheck %s --check-prefix VERSION
 
-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: OVERVIEW: LLVM TAPI file reader and manipulator
+; CHECK: USAGE: llvm-readtapi <command> [-arch <architecture> <options>]* <inputs> [-o <output>]*
+; CHECK: COMMANDS:
+; CHECK: OPTIONS:
+; 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
+; 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
 
+; VERSION: {{ version }}
diff --git a/llvm/tools/llvm-readtapi/TapiOpts.td b/llvm/tools/llvm-readtapi/TapiOpts.td
index 8fda035142a2ea..552690ce1385db 100644
--- a/llvm/tools/llvm-readtapi/TapiOpts.td
+++ b/llvm/tools/llvm-readtapi/TapiOpts.td
@@ -10,17 +10,19 @@ multiclass JS<string name, string help, string var = ""> {
 //
 // Top level operations 
 //
-def action_group : OptionGroup<"action group">;
+def action_group : OptionGroup<"action group">, HelpText<"COMMANDS">;
 def compare : FF<"compare", "compare tapi files for library differences">, Group<action_group>;
 def merge : FF<"merge", "merge the input files that represent the same library">, Group<action_group>;
-def extract: FF<"extract", "extract architecture from input file">, Group<action_group>;
-def remove: FF<"remove", "remove architecture from input file">, Group<action_group>;
+def extract: FF<"extract", "extract <architecture> from input file">, Group<action_group>;
+def remove: FF<"remove", "remove <architecture> from input file">, Group<action_group>;
 
 //
 // General Driver options 
 //
 def help : FF<"help", "display this help">;
+def version: FF<"version", "print the llvm-readtapi version">;
+def v: FF<"v", "alias for --version">, Alias<version>;
 defm output: JS<"o", "write output to <file>","<file>">;
 def compact: FF<"compact", "write compact tapi output file">;
 defm filetype: JS<"filetype", "specify the output file type (tbd-v3, tbd-v4 or tbd-v5)","<value>">;
-defm arch: JS<"arch", "specify the architecture", "<architecture>">;
+defm arch: JS<"arch", "specify the <architecture>", "<architecture>">;
diff --git a/llvm/tools/llvm-readtapi/llvm-readtapi.cpp b/llvm/tools/llvm-readtapi/llvm-readtapi.cpp
index 64eff70dbfc75d..def7508bb8c916 100644
--- a/llvm/tools/llvm-readtapi/llvm-readtapi.cpp
+++ b/llvm/tools/llvm-readtapi/llvm-readtapi.cpp
@@ -171,12 +171,18 @@ int main(int Argc, char **Argv) {
       Argc, Argv, OPT_UNKNOWN, Saver, [&](StringRef Msg) { reportError(Msg); });
   if (Args.hasArg(OPT_help)) {
     Tbl.printHelp(outs(),
-                  "USAGE: llvm-readtapi [options] [-arch <arch>]* <inputs> [-o "
+                  "USAGE: llvm-readtapi <command> [-arch <architecture> "
+                  "<options>]* <inputs> [-o "
                   "<output>]*",
                   "LLVM TAPI file reader and manipulator");
     return EXIT_SUCCESS;
   }
 
+  if (Args.hasArg(OPT_version)) {
+    cl::PrintVersionMessage();
+    return EXIT_SUCCESS;
+  }
+
   for (opt::Arg *A : Args.filtered(OPT_INPUT))
     Ctx.Inputs.push_back(A->getValue());
 



More information about the llvm-commits mailing list