Compare commits

...

2 Commits

Author SHA1 Message Date
Jez Cope 2db31f13d8 Group alias commands under `alias` subcommand 2021-07-03 19:47:44 +01:00
Jez Cope 1b669b8733 Remove redundant args 2021-07-03 19:47:34 +01:00
1 changed files with 35 additions and 28 deletions

View File

@ -13,12 +13,7 @@ use clap::SubCommand;
#[tokio::main]
async fn main() -> Result<()> {
let matches = app_from_crate!()
.args_from_usage(
"-c, --config=[FILE] 'Sets custom config file'
-v, --verbose 'Prints more details when running'
-T, --token=[TOKEN] 'Specifies token for authentication'",
)
let app = app_from_crate!()
.subcommand(
SubCommand::with_name("login")
.about("authenticates and saves the session details")
@ -28,35 +23,47 @@ async fn main() -> Result<()> {
.subcommand(SubCommand::with_name("status").about("displays current session status"))
.subcommand(SubCommand::with_name("list-rooms").about("lists rooms available to the user"))
.subcommand(
SubCommand::with_name("add-alias")
.about("adds an alias to a room")
.args_from_usage(
"<ROOM_ID> 'The ID of the room to alias'
<ALIAS> 'The new alias to add'",
SubCommand::with_name("alias")
.about("alias subcommands")
.subcommand(
SubCommand::with_name("add")
.about("adds an alias to a room")
.args_from_usage(
"<ROOM_ID> 'The ID of the room to alias'
<ALIAS> 'The new alias to add'",
),
)
.subcommand(
SubCommand::with_name("delete")
.about("deletes an existing alias")
.args_from_usage("<ALIAS> 'The alias to delete'"),
),
)
.subcommand(
SubCommand::with_name("del-alias")
.about("deletes an existing alias")
.args_from_usage("<ALIAS> 'The alias to delete'"),
)
.get_matches();
);
let matches = app.get_matches();
match matches.subcommand() {
("login", Some(submatches)) => commands::login(submatches.value_of("user")).await?,
("status", Some(_)) => commands::status().await?,
("list-rooms", Some(_)) => commands::list_rooms().await?,
("add-alias", Some(submatches)) => {
commands::add_alias(
submatches.value_of("ROOM_ID").unwrap(),
submatches.value_of("ALIAS").unwrap(),
)
.await?
("alias", Some(alias)) => match alias.subcommand() {
("add", Some(submatches)) => {
commands::add_alias(
submatches.value_of("ROOM_ID").unwrap(),
submatches.value_of("ALIAS").unwrap(),
)
.await?
}
("delete", Some(submatches)) => {
commands::del_alias(submatches.value_of("ALIAS").unwrap()).await?
}
(c, _) => {
todo!("Subcommand '{}' not implemented yet!", c);
}
},
("", None) => {
let mut out = io::stdout();
app.write_long_help(&mut out).unwrap();
}
("del-alias", Some(submatches)) => {
commands::del_alias(submatches.value_of("ALIAS").unwrap()).await?
}
("", None) => bail!("No subcommand given"),
(c, _) => {
todo!("Subcommand '{}' not implemented yet!", c);
}