fix(clap): print usage if command is missing

Also, fixed config-dir substitution in flag's help message
This commit is contained in:
Sebastian Thiel
2015-04-29 22:05:45 +02:00
parent 5320a48e68
commit 63e23dd48f
3 changed files with 4 additions and 2 deletions

View File

@@ -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',
))

View File

@@ -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();
}
}

View File

@@ -351,7 +351,7 @@ impl fmt::Display for CLIError {
writeln!(f, "'{}' does not match {}pattern <key>=<value>", 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),
}
}
}