From 63e23dd48f7fb80268eb3bc95380b77b233de62a Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 29 Apr 2015 22:05:45 +0200 Subject: [PATCH] fix(clap): print usage if command is missing Also, fixed config-dir substitution in flag's help message --- src/mako/cli/lib/argparse.mako | 2 +- src/mako/cli/lib/engine.mako | 2 ++ src/rust/cli/cmn.rs | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/mako/cli/lib/argparse.mako b/src/mako/cli/lib/argparse.mako index dbf237b4ee..71fe6e958c 100644 --- a/src/mako/cli/lib/argparse.mako +++ b/src/mako/cli/lib/argparse.mako @@ -104,7 +104,7 @@ Configuration: CONFIG_DIR_FLAG, "A directory into which we will store our persistent data. Defaults to " "a user-writable directory that we will create during the first invocation." - "[default: ${CONFIG_DIR}]", + "[default: %s" % CONFIG_DIR, 'folder', )) diff --git a/src/mako/cli/lib/engine.mako b/src/mako/cli/lib/engine.mako index 93c256eb3a..d53cad5245 100644 --- a/src/mako/cli/lib/engine.mako +++ b/src/mako/cli/lib/engine.mako @@ -69,12 +69,14 @@ impl<'n, 'a> Engine<'n, 'a> { % endfor # each method _ => { err.issues.push(CLIError::MissingMethodError("${mangle_subcommand(resource)}".to_string())); + writeln!(io::stderr(), "{}\n", opt.usage()).ok(); } } }, % endfor # each resource _ => { err.issues.push(CLIError::MissingCommandError); + writeln!(io::stderr(), "{}\n", ${SOPT}.usage()).ok(); } } diff --git a/src/rust/cli/cmn.rs b/src/rust/cli/cmn.rs index 1855e5289f..e814649843 100644 --- a/src/rust/cli/cmn.rs +++ b/src/rust/cli/cmn.rs @@ -351,7 +351,7 @@ impl fmt::Display for CLIError { writeln!(f, "'{}' does not match {}pattern =", kv, hashmap_info) }, CLIError::MissingCommandError => writeln!(f, "Please specify the main sub-command"), - CLIError::MissingMethodError(ref cmd) => writeln!(f, "Please specify the method to call on the {} command", cmd), + CLIError::MissingMethodError(ref cmd) => writeln!(f, "Please specify the method to call on the '{}' command", cmd), } } }