Add check if given subcommand is supported
This commit is contained in:
parent
e6d48cb31a
commit
7023d1f202
1 changed files with 9 additions and 0 deletions
|
@ -175,6 +175,13 @@ fn main() {
|
||||||
Some(values) => values.collect(),
|
Some(values) => values.collect(),
|
||||||
None => Vec::new()
|
None => Vec::new()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if !get_commands().contains(&String::from(subcommand)) {
|
||||||
|
println!("No such command: 'imag-{}'", subcommand);
|
||||||
|
println!("See 'imag --help' for available subcommands");
|
||||||
|
exit(2);
|
||||||
|
}
|
||||||
|
|
||||||
debug!("Calling 'imag-{}' with args: {:?}", subcommand, subcommand_args);
|
debug!("Calling 'imag-{}' with args: {:?}", subcommand, subcommand_args);
|
||||||
|
|
||||||
match Command::new(format!("imag-{}", subcommand))
|
match Command::new(format!("imag-{}", subcommand))
|
||||||
|
@ -198,6 +205,8 @@ fn main() {
|
||||||
debug!("Error calling the subcommand");
|
debug!("Error calling the subcommand");
|
||||||
match e.kind() {
|
match e.kind() {
|
||||||
ErrorKind::NotFound => {
|
ErrorKind::NotFound => {
|
||||||
|
// With the check above, this absolutely should not happen.
|
||||||
|
// Keeping it to be safe
|
||||||
println!("No such command: 'imag-{}'", subcommand);
|
println!("No such command: 'imag-{}'", subcommand);
|
||||||
println!("See 'imag --help' for available subcommands");
|
println!("See 'imag --help' for available subcommands");
|
||||||
exit(2);
|
exit(2);
|
||||||
|
|
Loading…
Reference in a new issue