|
|
|
@ -17,6 +17,8 @@
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
use clap::App; |
|
|
|
|
use clap::Arg; |
|
|
|
|
use clap::ArgMatches; |
|
|
|
|
use clap::SubCommand; |
|
|
|
|
|
|
|
|
|
/// Possible commands
|
|
|
|
@ -25,6 +27,10 @@ pub enum Command {
|
|
|
|
|
Unknown, |
|
|
|
|
/// Fetch all new favourites
|
|
|
|
|
Fetch, |
|
|
|
|
/// Add a new account with the specified name
|
|
|
|
|
AddAccount(String), |
|
|
|
|
/// Remove the account with the specified name
|
|
|
|
|
RemoveAccount(String), |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Parse the command line, returning the necessary command.
|
|
|
|
@ -33,11 +39,55 @@ pub fn parse() -> Command {
|
|
|
|
|
.version(clap::crate_version!()) |
|
|
|
|
.author(clap::crate_authors!()) |
|
|
|
|
.about(clap::crate_description!()) |
|
|
|
|
.subcommand(SubCommand::with_name("fetch").about("Fetch the new favourites")); |
|
|
|
|
.subcommand( |
|
|
|
|
SubCommand::with_name("fetch").about("Fetch the new favourites"), |
|
|
|
|
) |
|
|
|
|
.subcommand( |
|
|
|
|
SubCommand::with_name("account") |
|
|
|
|
.about("Manage Mastodon accounts") |
|
|
|
|
.subcommand( |
|
|
|
|
SubCommand::with_name("add") |
|
|
|
|
.about("Add a new account") |
|
|
|
|
.arg( |
|
|
|
|
Arg::with_name("name") |
|
|
|
|
.required(true) |
|
|
|
|
.takes_value(true) |
|
|
|
|
.help("Account name"), |
|
|
|
|
), |
|
|
|
|
) |
|
|
|
|
.subcommand( |
|
|
|
|
SubCommand::with_name("remove") |
|
|
|
|
.about("Remove an account") |
|
|
|
|
.arg( |
|
|
|
|
Arg::with_name("name") |
|
|
|
|
.required(true) |
|
|
|
|
.takes_value(true) |
|
|
|
|
.help("Name of the account to be removed"), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|
let matches = parser.get_matches(); |
|
|
|
|
match matches.subcommand() { |
|
|
|
|
("", _) => Command::Fetch, |
|
|
|
|
("fetch", _) => Command::Fetch, |
|
|
|
|
("account", Some(arguments)) => parse_account(arguments), |
|
|
|
|
_ => Command::Unknown, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn parse_account(arguments: &ArgMatches) -> Command { |
|
|
|
|
log::debug!("Parsing accounts"); |
|
|
|
|
match arguments.subcommand() { |
|
|
|
|
("add", Some(argument)) => { |
|
|
|
|
log::debug!("Must add new account"); |
|
|
|
|
let name = argument.value_of("name").unwrap(); |
|
|
|
|
Command::AddAccount(name.into()) |
|
|
|
|
} |
|
|
|
|
("remove", Some(argument)) => { |
|
|
|
|
log::debug!("Must remove account"); |
|
|
|
|
let name = argument.value_of("name").unwrap(); |
|
|
|
|
Command::RemoveAccount(name.into()) |
|
|
|
|
} |
|
|
|
|
_ => Command::Unknown, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|