[PATCH] D69501: [CommandLine] Add inline ArgName printing
Daan Sprenkels via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 28 02:44:16 PDT 2019
dsprenkels created this revision.
dsprenkels added reviewers: jhenderson, chandlerc.
dsprenkels added a project: LLVM.
Herald added subscribers: llvm-commits, kristina, hiraditya.
This patch adds PrintArgInline, after PrintArg which strips the
leading spaces from an argument before printing them, for usage
inline.
Related bug: PR42943 https://bugs.llvm.org/show_bug.cgi?id=42943
Repository:
rL LLVM
https://reviews.llvm.org/D69501
Files:
llvm/lib/Support/CommandLine.cpp
Index: llvm/lib/Support/CommandLine.cpp
===================================================================
--- llvm/lib/Support/CommandLine.cpp
+++ llvm/lib/Support/CommandLine.cpp
@@ -129,6 +129,19 @@
return OS;
}
+// Use for inline printing (omit leading spaces)
+class PrintArgInline {
+ StringRef ArgName;
+public:
+ PrintArgInline(StringRef ArgName) : ArgName(ArgName) {}
+ friend raw_ostream &operator<<(raw_ostream &OS, const PrintArgInline &);
+};
+
+raw_ostream &operator<<(raw_ostream &OS, const PrintArgInline &Arg) {
+ OS << argPrefix(Arg.ArgName).ltrim() << Arg.ArgName;
+ return OS;
+}
+
class CommandLineParser {
public:
// Globals for name and overview of program. Program name is not a string to
@@ -1447,7 +1460,7 @@
if (NearestHandler) {
// If we know a near match, report it as well.
*Errs << ProgramName << ": Did you mean '"
- << PrintArg(NearestHandlerString) << "'?\n";
+ << PrintArgInline(NearestHandlerString) << "'?\n";
}
ErrorParsing = true;
@@ -1601,7 +1614,7 @@
if (ArgName.empty())
Errs << HelpStr; // Be nice for positional arguments
else
- Errs << GlobalParser->ProgramName << ": for the " << PrintArg(ArgName);
+ Errs << GlobalParser->ProgramName << ": for the " << PrintArgInline(ArgName);
Errs << " option: " << Message << "\n";
return true;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69501.226624.patch
Type: text/x-patch
Size: 1402 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191028/b5a88e1f/attachment.bin>
More information about the llvm-commits
mailing list