[llvm] df42d63 - [obj2yaml] Refactor command line parsing
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 18 00:14:01 PDT 2022
Author: Fangrui Song
Date: 2022-07-18T00:13:55-07:00
New Revision: df42d63d3706133efa46d16d29492efd125a3e28
URL: https://github.com/llvm/llvm-project/commit/df42d63d3706133efa46d16d29492efd125a3e28
DIFF: https://github.com/llvm/llvm-project/commit/df42d63d3706133efa46d16d29492efd125a3e28.diff
LOG: [obj2yaml] Refactor command line parsing
Similar to D73982 for yaml2obj.
* Hide unrelated options.
* Add an OVERVIEW: message.
* Disallow single-dash long options.
Reviewed By: jhenderson
Differential Revision: https://reviews.llvm.org/D129839
Added:
llvm/test/tools/obj2yaml/help.test
Modified:
llvm/tools/obj2yaml/obj2yaml.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/obj2yaml/help.test b/llvm/test/tools/obj2yaml/help.test
new file mode 100644
index 0000000000000..72e8e75b7d158
--- /dev/null
+++ b/llvm/test/tools/obj2yaml/help.test
@@ -0,0 +1,11 @@
+## Show that help text is printed correctly when requested.
+
+# RUN: obj2yaml -h | FileCheck %s --check-prefixes=CHECK,CATEG --implicit-check-not=Options:
+# RUN: obj2yaml --help | FileCheck %s --check-prefixes=CHECK,CATEG --implicit-check-not=Options:
+# RUN: obj2yaml --help-list | FileCheck %s --implicit-check-not=Options:
+
+# CHECK: OVERVIEW: Dump a YAML description from an object file
+# CHECK: USAGE: obj2yaml{{(.exe)?}} [options] <input file>{{$}}
+# CHECK: OPTIONS:
+# CATEG: Generic Options:
+# CATEG: obj2yaml Options:
diff --git a/llvm/tools/obj2yaml/obj2yaml.cpp b/llvm/tools/obj2yaml/obj2yaml.cpp
index 4eec967d9fa6b..f1dbd5905f232 100644
--- a/llvm/tools/obj2yaml/obj2yaml.cpp
+++ b/llvm/tools/obj2yaml/obj2yaml.cpp
@@ -20,16 +20,20 @@
using namespace llvm;
using namespace llvm::object;
+static cl::OptionCategory Cat("obj2yaml Options");
+
static cl::opt<std::string>
InputFilename(cl::Positional, cl::desc("<input file>"), cl::init("-"));
static cl::opt<std::string> OutputFilename("o", cl::desc("Output filename"),
cl::value_desc("filename"),
- cl::init("-"), cl::Prefix);
+ cl::init("-"), cl::Prefix,
+ cl::cat(Cat));
static cl::bits<RawSegments> RawSegment(
"raw-segment",
cl::desc("Mach-O: dump the raw contents of the listed segments instead of "
"parsing them:"),
- cl::values(clEnumVal(data, "__DATA"), clEnumVal(linkedit, "__LINKEDIT")));
+ cl::values(clEnumVal(data, "__DATA"), clEnumVal(linkedit, "__LINKEDIT")),
+ cl::cat(Cat));
static Error dumpObject(const ObjectFile &Obj, raw_ostream &OS) {
if (Obj.isCOFF())
@@ -97,7 +101,10 @@ static void reportError(StringRef Input, Error Err) {
int main(int argc, char *argv[]) {
InitLLVM X(argc, argv);
- cl::ParseCommandLineOptions(argc, argv);
+ cl::HideUnrelatedOptions(Cat);
+ cl::ParseCommandLineOptions(
+ argc, argv, "Dump a YAML description from an object file", nullptr,
+ nullptr, /*LongOptionsUseDoubleDash=*/true);
std::error_code EC;
std::unique_ptr<ToolOutputFile> Out(
More information about the llvm-commits
mailing list