From 2db31f13d8bac5c29ea3ee49b352a3f409febe0b Mon Sep 17 00:00:00 2001 From: Jez Cope Date: Sat, 3 Jul 2021 19:47:44 +0100 Subject: [PATCH] Group alias commands under `alias` subcommand --- src/main.rs | 56 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/src/main.rs b/src/main.rs index 06e5cf5..4045479 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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( - " 'The ID of the room to 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( + " 'The ID of the room to alias' + 'The new alias to add'", + ), + ) + .subcommand( + SubCommand::with_name("delete") + .about("deletes an existing alias") + .args_from_usage(" 'The alias to delete'"), ), - ) - .subcommand( - SubCommand::with_name("del-alias") - .about("deletes an existing alias") - .args_from_usage(" '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); }