[PATCH] D105893: [llvm][tools] Hide unrelated llvm-bcanalyzer options

Timm Bäder via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 14 04:32:14 PDT 2021


tbaeder updated this revision to Diff 358557.
tbaeder added a comment.

It doesn't seem very useful to me to add tests for the help output. Since all categories are listed in the `HideUnrelatedOptions()` call anyway, new categories are not just gonna show up without changing that call. And this one test doesn't cover new tools that are going to be added either.

Added the suggested test case anyway, with some modifications to make it work.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105893/new/

https://reviews.llvm.org/D105893

Files:
  llvm/test/tools/llvm-bcanalyzer/help.test
  llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp


Index: llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
===================================================================
--- llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
+++ llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
@@ -32,37 +32,48 @@
 #include "llvm/Support/Error.h"
 #include "llvm/Support/InitLLVM.h"
 #include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/WithColor.h"
 #include "llvm/Support/raw_ostream.h"
 #include <memory>
 using namespace llvm;
 
-static cl::opt<std::string>
-    InputFilename(cl::Positional, cl::desc("<input bitcode>"), cl::init("-"));
+static cl::OptionCategory BCAnalyzerCategory("BC Analyzer Options");
+
+static cl::opt<std::string> InputFilename(cl::Positional,
+                                          cl::desc("<input bitcode>"),
+                                          cl::init("-"),
+                                          cl::cat(BCAnalyzerCategory));
 
-static cl::opt<bool> Dump("dump", cl::desc("Dump low level bitcode trace"));
+static cl::opt<bool> Dump("dump", cl::desc("Dump low level bitcode trace"),
+                          cl::cat(BCAnalyzerCategory));
 
 //===----------------------------------------------------------------------===//
 // Bitcode specific analysis.
 //===----------------------------------------------------------------------===//
 
 static cl::opt<bool> NoHistogram("disable-histogram",
-                                 cl::desc("Do not print per-code histogram"));
+                                 cl::desc("Do not print per-code histogram"),
+                                 cl::cat(BCAnalyzerCategory));
 
 static cl::opt<bool> NonSymbolic("non-symbolic",
                                  cl::desc("Emit numeric info in dump even if"
-                                          " symbolic info is available"));
+                                          " symbolic info is available"),
+                                 cl::cat(BCAnalyzerCategory));
 
 static cl::opt<std::string>
     BlockInfoFilename("block-info",
-                      cl::desc("Use the BLOCK_INFO from the given file"));
+                      cl::desc("Use the BLOCK_INFO from the given file"),
+                      cl::cat(BCAnalyzerCategory));
 
 static cl::opt<bool>
     ShowBinaryBlobs("show-binary-blobs",
-                    cl::desc("Print binary blobs using hex escapes"));
+                    cl::desc("Print binary blobs using hex escapes"),
+                    cl::cat(BCAnalyzerCategory));
 
 static cl::opt<std::string> CheckHash(
     "check-hash",
-    cl::desc("Check module hash using the argument as a string table"));
+    cl::desc("Check module hash using the argument as a string table"),
+    cl::cat(BCAnalyzerCategory));
 
 static Error reportError(StringRef Message) {
   return createStringError(std::errc::illegal_byte_sequence, Message.data());
@@ -85,6 +96,8 @@
 
 int main(int argc, char **argv) {
   InitLLVM X(argc, argv);
+
+  cl::HideUnrelatedOptions({&BCAnalyzerCategory, &ColorCategory});
   cl::ParseCommandLineOptions(argc, argv, "llvm-bcanalyzer file analyzer\n");
   ExitOnError ExitOnErr("llvm-bcanalyzer: ");
 
Index: llvm/test/tools/llvm-bcanalyzer/help.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-bcanalyzer/help.test
@@ -0,0 +1,7 @@
+# RUN: llvm-bcanalyzer --help | FileCheck %s --check-prefix HELP --implicit-check-not="General options:"
+
+# HELP: OVERVIEW
+# HELP: USAGE
+# HELP: BC Analyzer Options
+# HELP: Color Options
+# HELP: Generic Options


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105893.358557.patch
Type: text/x-patch
Size: 3547 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210714/8c6fc9ec/attachment.bin>


More information about the llvm-commits mailing list