Commit ab6bec4ccc
ab6bec4ccca9263401ce75983829aa56d4f5b03e
parent: 73656c0b1c
Unsigned
Damir Jelić <poljar@termina.org.uk> · 2021-07-21 19:34 UTC
fix(commands): Require a subcommand even if the command is a /matrix subcommand
This closes: #51.
Layout: unified · split
src/commands/devices.rs
+8 −4
| @@ -21,6 +21,13 @@ impl DevicesCommand { |
| 21 | 21 | pub const DESCRIPTION: &'static str = |
| 22 | 22 | "List, delete or rename Matrix devices"; |
| 23 | 23 | |
| 24 | pub const SETTINGS: &'static [ArgParseSettings] = &[ |
| 25 | ArgParseSettings::DisableHelpFlags, |
| 26 | ArgParseSettings::DisableVersion, |
| 27 | ArgParseSettings::VersionlessSubcommands, |
| 28 | ArgParseSettings::SubcommandRequiredElseHelp, |
| 29 | ]; |
| 30 | |
| 24 | 31 | pub fn create(servers: &Servers) -> Result<Command, ()> { |
| 25 | 32 | let settings = CommandSettings::new("devices") |
| 26 | 33 | .description(Self::DESCRIPTION) |
| @@ -115,10 +122,7 @@ impl CommandCallback for DevicesCommand { |
| 115 | 122 | fn callback(&mut self, _: &Weechat, buffer: &Buffer, arguments: Args) { |
| 116 | 123 | let argparse = Argparse::new("devices") |
| 117 | 124 | .about(Self::DESCRIPTION) |
| 118 | | .global_setting(ArgParseSettings::DisableHelpFlags) |
| 119 | | .global_setting(ArgParseSettings::DisableVersion) |
| 120 | | .global_setting(ArgParseSettings::VersionlessSubcommands) |
| 121 | | .setting(ArgParseSettings::SubcommandRequiredElseHelp) |
| 125 | .settings(Self::SETTINGS) |
| 122 | 126 | .subcommands(Self::subcommands()); |
| 123 | 127 | |
| 124 | 128 | parse_and_run(argparse, arguments, |matches| { |
src/commands/keys.rs
+7 −4
| @@ -21,6 +21,12 @@ pub struct KeysCommand { |
| 21 | 21 | impl KeysCommand { |
| 22 | 22 | pub const DESCRIPTION: &'static str = "Import or export E2EE keys."; |
| 23 | 23 | pub const COMPLETION: &'static str = "import|export %(filename)"; |
| 24 | pub const SETTINGS: &'static [ArgParseSettings] = &[ |
| 25 | ArgParseSettings::DisableHelpFlags, |
| 26 | ArgParseSettings::DisableVersion, |
| 27 | ArgParseSettings::VersionlessSubcommands, |
| 28 | ArgParseSettings::SubcommandRequiredElseHelp, |
| 29 | ]; |
| 24 | 30 | |
| 25 | 31 | pub fn create(servers: &Servers) -> Result<Command, ()> { |
| 26 | 32 | let settings = CommandSettings::new("keys") |
| @@ -116,10 +122,7 @@ impl CommandCallback for KeysCommand { |
| 116 | 122 | fn callback(&mut self, _: &Weechat, buffer: &Buffer, arguments: Args) { |
| 117 | 123 | let argparse = Argparse::new("keys") |
| 118 | 124 | .about(Self::DESCRIPTION) |
| 119 | | .global_setting(ArgParseSettings::DisableHelpFlags) |
| 120 | | .global_setting(ArgParseSettings::DisableVersion) |
| 121 | | .global_setting(ArgParseSettings::VersionlessSubcommands) |
| 122 | | .setting(ArgParseSettings::SubcommandRequiredElseHelp) |
| 125 | .settings(Self::SETTINGS) |
| 123 | 126 | .subcommands(Self::subcommands()); |
| 124 | 127 | |
| 125 | 128 | parse_and_run(argparse, arguments, |matches| { |
src/commands/matrix.rs
+7 −3
| @@ -272,19 +272,23 @@ impl CommandCallback for MatrixCommand { |
| 272 | 272 | |
| 273 | 273 | let argparse = Argparse::new("matrix") |
| 274 | 274 | .about("Matrix chat protocol command.") |
| 275 | | .global_setting(ArgParseSettings::DisableHelpFlags) |
| 276 | | .global_setting(ArgParseSettings::DisableVersion) |
| 277 | | .global_setting(ArgParseSettings::VersionlessSubcommands) |
| 275 | .global_settings(&[ |
| 276 | ArgParseSettings::DisableHelpFlags, |
| 277 | ArgParseSettings::DisableVersion, |
| 278 | ArgParseSettings::VersionlessSubcommands, |
| 279 | ]) |
| 278 | 280 | .setting(ArgParseSettings::SubcommandRequiredElseHelp) |
| 279 | 281 | .subcommand(server_command) |
| 280 | 282 | .subcommand( |
| 281 | 283 | SubCommand::with_name("devices") |
| 282 | 284 | .about(DevicesCommand::DESCRIPTION) |
| 285 | .settings(DevicesCommand::SETTINGS) |
| 283 | 286 | .subcommands(DevicesCommand::subcommands()), |
| 284 | 287 | ) |
| 285 | 288 | .subcommand( |
| 286 | 289 | SubCommand::with_name("keys") |
| 287 | 290 | .about(KeysCommand::DESCRIPTION) |
| 291 | .settings(KeysCommand::SETTINGS) |
| 288 | 292 | .subcommands(KeysCommand::subcommands()), |
| 289 | 293 | ) |
| 290 | 294 | .subcommand( |