diff options
author | Jesse Luehrs <doy@tozt.net> | 2018-11-10 05:16:40 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2018-11-10 05:16:40 -0500 |
commit | c22141ea46b406003eb889a8408d9b87e6b488fa (patch) | |
tree | cbf4a1d6c524676d1df60caa3e47f6afe243d178 | |
parent | 21ccf50a1705298273160d06eb2298d63403b34b (diff) | |
download | lastfm-query-c22141ea46b406003eb889a8408d9b87e6b488fa.tar.gz lastfm-query-c22141ea46b406003eb889a8408d9b87e6b488fa.zip |
better error reporting when no args given
-rw-r--r-- | src/cmd/mod.rs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs index 813a27a..021bc48 100644 --- a/src/cmd/mod.rs +++ b/src/cmd/mod.rs @@ -18,11 +18,11 @@ fn get_command() -> failure::Fallible<Box<Command>> { sql::subcommand(), recommend::subcommand(), ]; - let matches = app_from_crate!() + let mut app = app_from_crate!() .subcommands(subcommands.into_iter().map(|s| { s.setting(clap::AppSettings::DisableVersion) - })) - .get_matches(); + })); + let matches = app.clone().get_matches(); let command: Box<Command> = match matches.subcommand() { ("sync", Some(matches)) => Box::new(sync::Command::new(matches)), @@ -30,7 +30,12 @@ fn get_command() -> failure::Fallible<Box<Command>> { ("recommend", Some(matches)) => Box::new(recommend::Command::new(matches)?), (name, Some(_)) => bail!("unknown subcommand: {}", name), - (_, None) => bail!("no subcommand given"), + (_, None) => { + let mut stderr = std::io::stderr(); + app.write_long_help(&mut stderr)?; + eprintln!(""); + bail!("no subcommand given") + }, }; Ok(command) |