Browse Source

Fixed the args to have the storages directly, instead of args

master
Julio Biason 3 years ago
parent
commit
477d76e0d7
  1. 73
      src/args/mod.rs

73
src/args/mod.rs

@ -23,54 +23,69 @@ use clap::Arg;
use clap::SubCommand; use clap::SubCommand;
use self::errors::ParsingError; use self::errors::ParsingError;
use super::commands; use super::commands::Command;
/// Parse the command line, returning the necessary command. /// Parse the command line, returning the necessary command.
pub fn parse() -> Result<Box<dyn commands::Command>, ParsingError> { pub fn parse() -> Result<Command, ParsingError> {
let parser = App::new(clap::crate_name!()) let parser = App::new(clap::crate_name!())
.version(clap::crate_version!()) .version(clap::crate_version!())
.author(clap::crate_authors!()) .author(clap::crate_authors!())
.about(clap::crate_description!()) .about(clap::crate_description!())
.arg(Arg::with_name("account").help("Account alias").required(true)) .arg(
.subcommand( Arg::with_name("account")
SubCommand::with_name("create").about("Create the account"), .help("Account alias")
) .required(true),
.subcommand(
SubCommand::with_name("remove").about("Remove the account"),
) )
.subcommand(SubCommand::with_name("create").about("Create the account"))
.subcommand(SubCommand::with_name("remove").about("Remove the account"))
.subcommand( .subcommand(
SubCommand::with_name("fetch") SubCommand::with_name("fetch")
.about("Fetch new favourites from this account only") .about("Fetch new favourites from this account only"),
) )
.subcommand( .subcommand(
SubCommand::with_name("sync") 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(
SubCommand::with_name("storage") SubCommand::with_name("storage")
.about("Account storage") .about("Account storage")
.subcommand(SubCommand::with_name("add") .subcommand(
.about("Add a new storage for the account") SubCommand::with_name("add")
.arg(Arg::with_name("type") .about("Add a new storage for the account")
.help("Storage type; valid types are: \"filesystem\"") .subcommand(SubCommand::with_name("markdown").about(
.takes_value(true) "Store favourites on the filesystem, as markdown",
.required(true))) ))
.subcommand(SubCommand::with_name("remove") .subcommand(SubCommand::with_name("org").about(
.about("Remove a storage from the account") "Store favourites on the filesystem, as Org files",
.arg(Arg::with_name("type") ))
.help("Storage type to be removed") .subcommand(
.takes_value(true) SubCommand::with_name("joplin")
.required(true)))); .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 matches = parser.get_matches();
let account_name = matches.value_of("account").unwrap(); // we can unwrap 'cause it is required let account_name = matches.value_of("account").unwrap(); // we can unwrap 'cause it is required
match matches.subcommand() { match matches.subcommand() {
("create", _) => Ok(Box::new(commands::addaccount::AddAccount::new( ("create", _) => Ok(Command::add_account(account_name.into())),
account_name.into(), ("remove", _) => Ok(Command::remove_account(account_name.into())),
))),
("remove", _) => Ok(Box::new(
commands::removeaccount::RemoveAccount::new(account_name.into()),
)),
_ => Err(ParsingError::UnknownCommand), _ => Err(ParsingError::UnknownCommand),
} }
} }

Loading…
Cancel
Save