[PATCH] D73982: [yaml2obj] Refactor command line parsing
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 5 09:36:48 PST 2020
MaskRay updated this revision to Diff 242662.
MaskRay marked 3 inline comments as done.
MaskRay added a comment.
Address review comments
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D73982/new/
https://reviews.llvm.org/D73982
Files:
llvm/test/tools/yaml2obj/help.test
llvm/test/tools/yaml2obj/invalid-output-file.yaml
llvm/test/tools/yaml2obj/output-file.yaml
llvm/tools/yaml2obj/yaml2obj.cpp
Index: llvm/tools/yaml2obj/yaml2obj.cpp
===================================================================
--- llvm/tools/yaml2obj/yaml2obj.cpp
+++ llvm/tools/yaml2obj/yaml2obj.cpp
@@ -28,22 +28,28 @@
using namespace llvm;
-static cl::opt<std::string>
- Input(cl::Positional, cl::desc("<input>"), cl::init("-"));
+namespace {
+cl::OptionCategory Cat("yaml2obj Options");
-static cl::opt<unsigned>
+cl::opt<std::string> Input(cl::Positional, cl::desc("<input file>"),
+ cl::init("-"), cl::cat(Cat));
+
+cl::opt<unsigned>
DocNum("docnum", cl::init(1),
- cl::desc("Read specified document from input (default = 1)"));
+ cl::desc("Read specified document from input (default = 1)"),
+ cl::cat(Cat));
-static cl::opt<std::string> OutputFilename("o", cl::desc("Output filename"),
- cl::value_desc("filename"));
+cl::opt<std::string> OutputFilename("o", cl::desc("Output filename"),
+ cl::value_desc("filename"), cl::init("-"),
+ cl::Prefix, cl::cat(Cat));
+} // namespace
int main(int argc, char **argv) {
InitLLVM X(argc, argv);
- cl::ParseCommandLineOptions(argc, argv);
-
- if (OutputFilename.empty())
- OutputFilename = "-";
+ cl::HideUnrelatedOptions(Cat);
+ cl::ParseCommandLineOptions(
+ argc, argv, "Create an object file from a YAML description", nullptr,
+ nullptr, /*LongOptionsUseDoubleDash=*/true);
auto ErrHandler = [](const Twine &Msg) {
WithColor::error(errs(), "yaml2obj") << Msg << "\n";
Index: llvm/test/tools/yaml2obj/output-file.yaml
===================================================================
--- /dev/null
+++ llvm/test/tools/yaml2obj/output-file.yaml
@@ -0,0 +1,19 @@
+## Test that -o sets the output file name.
+
+# RUN: rm -f %t
+# RUN: yaml2obj %s -o %t
+# RUN: ls %t
+# RUN: rm -f %t
+# RUN: yaml2obj %s -o%t
+# RUN: ls %t
+
+# RUN: not yaml2obj -o %p/path/does/not/exist 2>&1 | FileCheck %s
+
+# CHECK: yaml2obj: error: failed to open '{{.*}}/path/does/not/exist': {{[Nn]}}o such file or directory
+
+!ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_NONE
Index: llvm/test/tools/yaml2obj/invalid-output-file.yaml
===================================================================
--- llvm/test/tools/yaml2obj/invalid-output-file.yaml
+++ /dev/null
@@ -1,4 +0,0 @@
-# RUN: not yaml2obj -o %p/path/does/not/exist 2>&1 | FileCheck %s
-
-## Don't check the OS-dependent message "No such file or directory".
-# CHECK: yaml2obj: error: failed to open '{{.*}}/path/does/not/exist': {{.*}}
Index: llvm/test/tools/yaml2obj/help.test
===================================================================
--- /dev/null
+++ llvm/test/tools/yaml2obj/help.test
@@ -0,0 +1,11 @@
+## Show that help text is printed correctly when requested.
+
+# RUN: yaml2obj -h | FileCheck %s --check-prefixes=CHECK,CATEG --implicit-check-not=Options:
+# RUN: yaml2obj --help | FileCheck %s --check-prefixes=CHECK,CATEG --implicit-check-not=Options:
+# RUN: yaml2obj --help-list | FileCheck %s --implicit-check-not=Options:
+
+# CHECK: OVERVIEW: Create an object file from YAML description
+# CHECK: USAGE: yaml2obj{{(.exe)?}} [options] <input file>{{$}}
+# CHECK: OPTIONS:
+# CATEG: Generic Options:
+# CATEG: yaml2obj Options:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73982.242662.patch
Type: text/x-patch
Size: 3394 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200205/cc46f8ad/attachment.bin>
More information about the llvm-commits
mailing list