Group alias commands under `alias` subcommand

This commit is contained in:
Jez Cope 2021-07-03 19:47:44 +01:00
parent 1b669b8733
commit 2db31f13d8
1 changed files with 34 additions and 22 deletions

View File

@ -23,35 +23,47 @@ async fn main() -> Result<()> {
.subcommand(SubCommand::with_name("status").about("displays current session status")) .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("list-rooms").about("lists rooms available to the user"))
.subcommand( .subcommand(
SubCommand::with_name("add-alias") SubCommand::with_name("alias")
.about("adds an alias to a room") .about("alias subcommands")
.args_from_usage( .subcommand(
"<ROOM_ID> 'The ID of the room to alias' SubCommand::with_name("add")
<ALIAS> 'The new alias to 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( let matches = app.get_matches();
SubCommand::with_name("del-alias")
.about("deletes an existing alias")
.args_from_usage("<ALIAS> 'The alias to delete'"),
)
.get_matches();
match matches.subcommand() { match matches.subcommand() {
("login", Some(submatches)) => commands::login(submatches.value_of("user")).await?, ("login", Some(submatches)) => commands::login(submatches.value_of("user")).await?,
("status", Some(_)) => commands::status().await?, ("status", Some(_)) => commands::status().await?,
("list-rooms", Some(_)) => commands::list_rooms().await?, ("list-rooms", Some(_)) => commands::list_rooms().await?,
("add-alias", Some(submatches)) => { ("alias", Some(alias)) => match alias.subcommand() {
commands::add_alias( ("add", Some(submatches)) => {
submatches.value_of("ROOM_ID").unwrap(), commands::add_alias(
submatches.value_of("ALIAS").unwrap(), submatches.value_of("ROOM_ID").unwrap(),
) submatches.value_of("ALIAS").unwrap(),
.await? )
.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, _) => { (c, _) => {
todo!("Subcommand '{}' not implemented yet!", c); todo!("Subcommand '{}' not implemented yet!", c);
} }