summaryrefslogtreecommitdiffstats
path: root/src/cli.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2018-11-08 02:23:16 -0500
committerJesse Luehrs <doy@tozt.net>2018-11-08 02:23:16 -0500
commit6d4abd89b2dfcdce0bd59d627a31e92fcc745c94 (patch)
tree891ce011366d9d6bec6fd9adfa56452715e0b212 /src/cli.rs
parentbd7c31233de96d96e16f9c15e22d014514f7a173 (diff)
downloadlastfm-query-6d4abd89b2dfcdce0bd59d627a31e92fcc745c94.tar.gz
lastfm-query-6d4abd89b2dfcdce0bd59d627a31e92fcc745c94.zip
better options handling
Diffstat (limited to 'src/cli.rs')
-rw-r--r--src/cli.rs24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 0c140e7..1976d93 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -1,15 +1,12 @@
const _DUMMY_DEPENDENCY: &'static str = include_str!("../Cargo.toml");
pub enum Command {
- Sync,
+ Sync {
+ username: String,
+ }
}
-pub struct Options {
- pub command: Command,
- pub username: Option<String>,
-}
-
-pub fn get_options() -> failure::Fallible<Options> {
+pub fn get_options() -> failure::Fallible<Command> {
let matches = app_from_crate!()
.subcommand(
clap::SubCommand::with_name("sync")
@@ -22,14 +19,15 @@ pub fn get_options() -> failure::Fallible<Options> {
)
.get_matches();
- let (command, sub_matches) = match matches.subcommand() {
- ("sync", Some(matches)) => (Command::Sync, matches),
+ let command = match matches.subcommand() {
+ ("sync", Some(matches)) => {
+ Command::Sync {
+ username: matches.value_of("username").unwrap().to_string(),
+ }
+ },
(name, Some(_)) => bail!("unknown subcommand: {}", name),
(_, None) => bail!("no subcommand given"),
};
- Ok(Options {
- command: command,
- username: sub_matches.value_of("username").map(|s| s.to_string()),
- })
+ Ok(command)
}