Skip to content

Commit 09aee37

Browse files
committed
Merge #3: Print help if run without a subcommand
a79d139 cli: print help if no subcommand given (Andrew Cann) Pull request description: Builds on #1 Print help/usage info if run without a subcommand instead of printing `Execution failed: Subcommand not found:` ACKs for top commit: apoelstra: ACK a79d139; successfully ran local tests; nice! Tree-SHA512: a3b1d9f30cdedfa51f09782572f0513078d958807bd41b65b147676ca12df0d07113f1b1ffd18c7564af2beb979c6cb8dbd746c3145b58bcb2245569eeaf62b9
2 parents 85b57cb + a79d139 commit 09aee37

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/bin/hal-simplicity/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ fn init_app<'a, 'b>() -> clap::App<'a, 'b> {
3232
.setting(clap::AppSettings::AllArgsOverrideSelf)
3333
.subcommands(cmd::subcommands()),
3434
)
35+
.setting(clap::AppSettings::SubcommandRequiredElseHelp)
3536
.arg(
3637
cmd::opt("verbose", "print verbose logging output to stderr")
3738
.short("v")
@@ -84,6 +85,6 @@ fn main() {
8485
panic!("Subcommand not found: {}", m.subcommand().0);
8586
}
8687
}
87-
(cmd, _) => panic!("Subcommand not found: {}", cmd),
88+
(cmd, _) => panic!("Subcommand not found: {:?}", cmd),
8889
}
8990
}

tests/cli.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,24 @@ fn assert_cmd(args: &[&str], expected_stdout: impl AsRef<str>, expected_stderr:
4747

4848
#[test]
4949
fn cli_empty() {
50-
// FIXME this is definitely not what we want to show the user
5150
assert_cmd(
5251
&[],
52+
"",
5353
"\
54-
Execution failed: Subcommand not found:
54+
hal-simplicity 0.2.1
55+
56+
USAGE:
57+
hal [FLAGS] <SUBCOMMAND>
58+
59+
FLAGS:
60+
-h, --help Prints help information
61+
-V, --version Prints version information
62+
-v, --verbose print verbose logging output to stderr
63+
64+
SUBCOMMANDS:
65+
elements hal-simplicity -- a Simplicity extension of hal
66+
help Prints this message or the help of the given subcommand(s)
5567
",
56-
"",
5768
);
5869
}
5970

@@ -63,7 +74,7 @@ fn cli_help() {
6374
hal-simplicity 0.2.1
6475
6576
USAGE:
66-
hal [FLAGS] [SUBCOMMAND]
77+
hal [FLAGS] <SUBCOMMAND>
6778
6879
FLAGS:
6980
-h, --help Prints help information
@@ -88,7 +99,7 @@ fn cli_bad_flag() {
8899
error: Found argument '-?' which wasn't expected, or isn't valid in this context
89100
90101
USAGE:
91-
hal [FLAGS] [SUBCOMMAND]
102+
hal [FLAGS] <SUBCOMMAND>
92103
93104
For more information try --help
94105
",

0 commit comments

Comments
 (0)