From 477d76e0d78fa64e22319b92094c8d21ada77709 Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Thu, 24 Jun 2021 12:55:46 -0300 Subject: [PATCH] Fixed the args to have the storages directly, instead of args --- src/args/mod.rs | 73 +++++++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 29 deletions(-) diff --git a/src/args/mod.rs b/src/args/mod.rs index 9d45b3f..2e14220 100644 --- a/src/args/mod.rs +++ b/src/args/mod.rs @@ -23,54 +23,69 @@ use clap::Arg; use clap::SubCommand; use self::errors::ParsingError; -use super::commands; +use super::commands::Command; /// Parse the command line, returning the necessary command. -pub fn parse() -> Result, ParsingError> { +pub fn parse() -> Result { let parser = App::new(clap::crate_name!()) .version(clap::crate_version!()) .author(clap::crate_authors!()) .about(clap::crate_description!()) - .arg(Arg::with_name("account").help("Account alias").required(true)) - .subcommand( - SubCommand::with_name("create").about("Create the account"), - ) - .subcommand( - SubCommand::with_name("remove").about("Remove the account"), + .arg( + Arg::with_name("account") + .help("Account alias") + .required(true), ) + .subcommand(SubCommand::with_name("create").about("Create the account")) + .subcommand(SubCommand::with_name("remove").about("Remove the account")) .subcommand( SubCommand::with_name("fetch") - .about("Fetch new favourites from this account only") + .about("Fetch new favourites from this account only"), ) .subcommand( SubCommand::with_name("sync") - .about("Sync the last seen favourite with the most recent one") + .about("Sync the last seen favourite with the most recent one"), ) .subcommand( SubCommand::with_name("storage") - .about("Account storage") - .subcommand(SubCommand::with_name("add") - .about("Add a new storage for the account") - .arg(Arg::with_name("type") - .help("Storage type; valid types are: \"filesystem\"") - .takes_value(true) - .required(true))) - .subcommand(SubCommand::with_name("remove") - .about("Remove a storage from the account") - .arg(Arg::with_name("type") - .help("Storage type to be removed") - .takes_value(true) - .required(true)))); + .about("Account storage") + .subcommand( + SubCommand::with_name("add") + .about("Add a new storage for the account") + .subcommand(SubCommand::with_name("markdown").about( + "Store favourites on the filesystem, as markdown", + )) + .subcommand(SubCommand::with_name("org").about( + "Store favourites on the filesystem, as Org files", + )) + .subcommand( + SubCommand::with_name("joplin") + .about("Store favourites on Joplin"), + ), + ) + .subcommand( + SubCommand::with_name("remove") + .about("Remove a storage from the account") + .subcommand( + SubCommand::with_name("markdown") + .about("Remove the markdown storage"), + ) + .subcommand( + SubCommand::with_name("org") + .about("Remove the org storage"), + ) + .subcommand( + SubCommand::with_name("joplin") + .about("Remove the joplin storage"), + ), + ), + ); let matches = parser.get_matches(); let account_name = matches.value_of("account").unwrap(); // we can unwrap 'cause it is required match matches.subcommand() { - ("create", _) => Ok(Box::new(commands::addaccount::AddAccount::new( - account_name.into(), - ))), - ("remove", _) => Ok(Box::new( - commands::removeaccount::RemoveAccount::new(account_name.into()), - )), + ("create", _) => Ok(Command::add_account(account_name.into())), + ("remove", _) => Ok(Command::remove_account(account_name.into())), _ => Err(ParsingError::UnknownCommand), } }