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("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);
}