-
Notifications
You must be signed in to change notification settings - Fork 10.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CommandLine] Show '[subcommand]' in the help for less than 3 subcommands #74557
Conversation
@llvm/pr-subscribers-llvm-support Author: Igor Kudrin (igorkudrin) ChangesWhen a tool defines only one or two subcommands, the Full diff: https://github.com/llvm/llvm-project/pull/74557.diff 1 Files Affected:
diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp
index a7e0cae8b855d..31f79972125da 100644
--- a/llvm/lib/Support/CommandLine.cpp
+++ b/llvm/lib/Support/CommandLine.cpp
@@ -2372,7 +2372,7 @@ class HelpPrinter {
if (Sub == &SubCommand::getTopLevel()) {
outs() << "USAGE: " << GlobalParser->ProgramName;
- if (Subs.size() > 2)
+ if (!Subs.empty())
outs() << " [subcommand]";
outs() << " [options]";
} else {
|
I can't find an easy way to test this change. PS The buildbot failures do not seem relevant, as the patch could not cause crashes. |
I guess more unit-testability would be nice to have sooner or later as this library gets wider adoption. Whether or not you want to sign up for that now is a more open question, probably. How were similar changes tested? Perhaps tested with a concrete usage like clang, etc? Maybe one of these users has a case that would demonstrate the change/fix? |
236e9a4
to
1722d54
Compare
Hmm, I was under the impression that gtest runs unit tests in parallel, so it is not possible to intercept stdout. But in fact, gtest is single-threaded, and moreover, there are other tests in the test suite that already intercept the stream. So I added tests for the change to the patch. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Strange that the original patch (79f3333) used > 2
for "at least 1". I wonder if some refactoring later caused the issue?
1722d54
to
1d25851
Compare
Thanks. I guess that it was made to match the condition |
…ands When a tool defines only one or two subcommands, the `[subcommand]` part is not displayed in the `USAGE` help line. Note that a similar issue with printing the list of the subcommands has been fixed in https://reviews.llvm.org/D25463.
1d25851
to
7b056b8
Compare
When a tool defines only one or two subcommands, the
[subcommand]
part is not displayed in theUSAGE
help line. Note that a similar issue with printing the list of the subcommands has been fixed in https://reviews.llvm.org/D25463.