diff options
| author | Eskil Queseth <eskilq@kth.se> | 2021-03-29 21:56:03 +0200 |
|---|---|---|
| committer | Eskil Queseth <eskilq@kth.se> | 2021-03-29 21:56:03 +0200 |
| commit | bd0ea6ebd527eada9c428ed8ff78a9568bcc2e57 (patch) | |
| tree | 20eb237e49094ee5575ad0fc231fb401aa5c0616 /mumctl | |
| parent | c6a5774443099c747bce938e6f87299397819c2b (diff) | |
| download | mum-bd0ea6ebd527eada9c428ed8ff78a9568bcc2e57.tar.gz | |
change CLI for muting someone
Diffstat (limited to 'mumctl')
| -rw-r--r-- | mumctl/src/main.rs | 109 |
1 files changed, 35 insertions, 74 deletions
diff --git a/mumctl/src/main.rs b/mumctl/src/main.rs index 9d9e4fd..c22e9d2 100644 --- a/mumctl/src/main.rs +++ b/mumctl/src/main.rs @@ -159,32 +159,21 @@ fn main() { ) .subcommand( SubCommand::with_name("mute") - .about("Mute/unmute yourself") - .subcommand(SubCommand::with_name("true").alias("1")) - .subcommand(SubCommand::with_name("false").alias("0")) - .subcommand(SubCommand::with_name("toggle")) - .setting(AppSettings::SubcommandRequiredElseHelp), + .about("Mute someone/yourself") + .arg(Arg::with_name("user")) + ) + .subcommand( + SubCommand::with_name("unmute") + .about("Unmute someone/yourself") + .arg(Arg::with_name("user")) ) .subcommand( SubCommand::with_name("deafen") - .about("Deafen/undeafen yourself") - .subcommand(SubCommand::with_name("true").alias("1")) - .subcommand(SubCommand::with_name("false").alias("0")) - .subcommand(SubCommand::with_name("toggle")) - .setting(AppSettings::SubcommandRequiredElseHelp), + .about("Deafen yourself") ) .subcommand( - SubCommand::with_name("user") - .about("Configure someone else") - .arg(Arg::with_name("user").required(true)) - .subcommand( - SubCommand::with_name("mute") - .subcommand(SubCommand::with_name("true").alias("1")) - .subcommand(SubCommand::with_name("false").alias("0")) - .subcommand(SubCommand::with_name("toggle")) - .setting(AppSettings::SubcommandRequiredElseHelp), - ) - .setting(AppSettings::SubcommandRequiredElseHelp), + SubCommand::with_name("undeafen") + .about("Undeafen yourself") ); let matches = app.clone().get_matches(); @@ -327,62 +316,34 @@ fn process_matches(matches: ArgMatches, config: &mut Config, app: &mut App) -> R //needs work on mumd to implement } } else if let Some(matches) = matches.subcommand_matches("mute") { - let command = - Command::MuteSelf(if let Some(_matches) = matches.subcommand_matches("true") { - Some(true) - } else if let Some(_matches) = matches.subcommand_matches("false") { - Some(false) - } else if let Some(_matches) = matches.subcommand_matches("toggle") { - None - } else { - unreachable!() - }); - match send_command(command)? { - Ok(Some(CommandResponse::MuteStatus { is_muted })) => println!("{}", if is_muted { - "Muted" - } else { - "Unmuted" - }), - Ok(_) => {}, - Err(e) => error!("{}", e), - } - } else if let Some(matches) = matches.subcommand_matches("deafen") { - let command = - Command::DeafenSelf(if let Some(_matches) = matches.subcommand_matches("true") { - Some(true) - } else if let Some(_matches) = matches.subcommand_matches("false") { - Some(false) - } else if let Some(_matches) = matches.subcommand_matches("toggle") { - None - } else { - unreachable!() - }); - match send_command(command)? { - Ok(Some(CommandResponse::DeafenStatus { is_deafened })) => println!("{}", if is_deafened { - "Deafened" - } else { - "Undeafened" - }), - Ok(_) => {}, - Err(e) => error!("{}", e), + let command = if let Some(user) = matches.value_of("user") { + Command::MuteOther(user.to_string(), Some(true)) + } else { + Command::MuteSelf(Some(true)) + }; + if let Err(e) = send_command(command)? { + error!("{}", e); } - } else if let Some(matches) = matches.subcommand_matches("user") { - let name = matches.value_of("user").unwrap(); - if let Some(matches) = matches.subcommand_matches("mute") { - let toggle = if let Some(_matches) = matches.subcommand_matches("true") { - Some(true) - } else if let Some(_matches) = matches.subcommand_matches("false") { - Some(false) - } else if let Some(_matches) = matches.subcommand_matches("toggle") { - None - } else { - unreachable!() - }; - error_if_err!(send_command(Command::MuteOther(name.to_string(), toggle))); + } else if let Some(matches) = matches.subcommand_matches("unmute") { + let command = if let Some(user) = matches.value_of("user") { + Command::MuteOther(user.to_string(), Some(false)) } else { - unreachable!(); + Command::MuteSelf(Some(false)) + }; + if let Err(e) = send_command(command)? { + error!("{}", e); } - }; + } else if let Some(_) = matches.subcommand_matches("deafen") { + if let Err(e) = send_command(Command::DeafenSelf(Some(true)))? { + error!("{}", e); + } + } else if let Some(_) = matches.subcommand_matches("undeafen") { + if let Err(e) = send_command(Command::DeafenSelf(Some(false)))? { + error!("{}", e); + } + } else { + unreachable!(); + } Ok(()) } |
