Commit 0e9ec008a2

0e9ec008a21697f5b747aec1d37ee95e86ebbe54

parent: b7496cc732

Unsigned

Damir Jelić <poljar@termina.org.uk> · 2020-10-18 08:44 UTC

commands: Allow the keys command to be run as a matrix subcommand.

Layout: unified · split

src/commands/keys.rs +2 −2
@@ -19,6 +19,7 @@ pub struct KeysCommand {
1919
2020impl KeysCommand {
2121 pub const DESCRIPTION: &'static str = "Import or export E2EE keys.";
22 pub const COMPLETION: &'static str = "import|export %(filename)";
2223
2324 pub fn create(servers: &Servers) -> Result<Command, ()> {
2425 let settings = CommandSettings::new("keys")
@@ -29,8 +30,7 @@ impl KeysCommand {
2930 .arguments_description(
3031 "file: Path to a file that is or will contain the E2EE keys export",
3132 )
32 .add_completion("import %(filename)")
33 .add_completion("export %(filename)")
33 .add_completion(Self::COMPLETION)
3434 .add_completion("help import|export");
3535
3636 Command::new(
src/commands/matrix.rs +16 −3
@@ -11,8 +11,9 @@ use weechat::{
1111};
1212
1313use crate::{
14 commands::DevicesCommand, config::ConfigHandle, MatrixServer, Servers,
15 PLUGIN_NAME,
14 commands::{DevicesCommand, KeysCommand},
15 config::ConfigHandle,
16 MatrixServer, Servers, PLUGIN_NAME,
1617};
1718
1819pub struct MatrixCommand {
@@ -31,6 +32,7 @@ impl MatrixCommand {
3132 .add_argument("server delete|list|listfull <server-name>")
3233 .add_argument("connect <server-name>")
3334 .add_argument("devices delete|list|set-name")
35 .add_argument("keys import|export <file> <passphrase>")
3436 .add_argument("disconnect <server-name>")
3537 .add_argument("reconnect <server-name>")
3638 .add_argument("help <matrix-command> [<matrix-subcommand>]")
@@ -40,12 +42,15 @@ impl MatrixCommand {
4042 disconnect: Disconnect from one or all Matrix servers.
4143 reconnect: Reconnect to server(s).
4244 devices: {}
45 keys: {}
4346 help: Show detailed command help.\n
4447Use /matrix [command] help to find out more.\n",
45 DevicesCommand::DESCRIPTION
48 DevicesCommand::DESCRIPTION,
49 KeysCommand::DESCRIPTION,
4650 ))
4751 .add_completion("server |add|delete|list|listfull")
4852 .add_completion("devices |list|delete|set-name")
53 .add_completion(&format!("keys {}", KeysCommand::COMPLETION))
4954 .add_completion("connect")
5055 .add_completion("disconnect")
5156 .add_completion("reconnect")
@@ -266,6 +271,11 @@ impl CommandCallback for MatrixCommand {
266271 .about(DevicesCommand::DESCRIPTION)
267272 .subcommands(DevicesCommand::subcommands()),
268273 )
274 .subcommand(
275 SubCommand::with_name("keys")
276 .about(KeysCommand::DESCRIPTION)
277 .subcommands(KeysCommand::subcommands()),
278 )
269279 .subcommand(
270280 SubCommand::with_name("connect")
271281 .about("Connect to Matrix servers.")
@@ -308,6 +318,9 @@ impl CommandCallback for MatrixCommand {
308318 ("devices", Some(subargs)) => {
309319 DevicesCommand::run(buffer, &self.servers, subargs)
310320 }
321 ("keys", Some(subargs)) => {
322 KeysCommand::run(buffer, &self.servers, subargs)
323 }
311324 _ => unreachable!(),
312325 }
313326 }