Commit 202dc75836
Unsigned
Layout: unified · split
src/commands/mod.rs +35 −31
| @@ -20,6 +20,38 @@ struct MatrixCommand { | |||
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | impl MatrixCommand { | 22 | impl MatrixCommand { |
| 23 | fn new(servers: &Servers, config: &ConfigHandle) -> Result<Command, ()> { | ||
| 24 | let matrix_settings = CommandSettings::new("matrix") | ||
| 25 | .description("Matrix chat protocol command.") | ||
| 26 | .add_argument("server add <server-name> <hostname>[:<port>]") | ||
| 27 | .add_argument("server delete|list|listfull <server-name>") | ||
| 28 | .add_argument("connect <server-name>") | ||
| 29 | .add_argument("disconnect <server-name>") | ||
| 30 | .add_argument("reconnect <server-name>") | ||
| 31 | .add_argument("help <matrix-command> [<matrix-subcommand>]") | ||
| 32 | .arguments_description( | ||
| 33 | " server: List, add, or remove Matrix servers. | ||
| 34 | connect: Connect to Matrix servers. | ||
| 35 | disconnect: Disconnect from one or all Matrix servers. | ||
| 36 | reconnect: Reconnect to server(s). | ||
| 37 | help: Show detailed command help.\n | ||
| 38 | Use /matrix [command] help to find out more.\n", | ||
| 39 | ) | ||
| 40 | .add_completion("server |add|delete|list|listfull") | ||
| 41 | .add_completion("connect") | ||
| 42 | .add_completion("disconnect") | ||
| 43 | .add_completion("reconnect") | ||
| 44 | .add_completion("help server|connect|disconnect|reconnect"); | ||
| 45 | |||
| 46 | Command::new( | ||
| 47 | matrix_settings, | ||
| 48 | MatrixCommand { | ||
| 49 | servers: servers.clone(), | ||
| 50 | config: config.clone(), | ||
| 51 | }, | ||
| 52 | ) | ||
| 53 | } | ||
| 54 | |||
| 23 | fn add_server(&self, args: &ArgMatches) { | 55 | fn add_server(&self, args: &ArgMatches) { |
| 24 | let server_name = args | 56 | let server_name = args |
| 25 | .value_of("name") | 57 | .value_of("name") |
| @@ -271,36 +303,8 @@ impl Commands { | |||
| 271 | servers: &Servers, | 303 | servers: &Servers, |
| 272 | config: &ConfigHandle, | 304 | config: &ConfigHandle, |
| 273 | ) -> Result<Commands, ()> { | 305 | ) -> Result<Commands, ()> { |
| 274 | let matrix_settings = CommandSettings::new("matrix") | 306 | Ok(Commands { |
| 275 | .description("Matrix chat protocol command.") | 307 | _matrix: MatrixCommand::new(servers, config)?, |
| 276 | .add_argument("server add <server-name> <hostname>[:<port>]") | 308 | }) |
| 277 | .add_argument("server delete|list|listfull <server-name>") | ||
| 278 | .add_argument("connect <server-name>") | ||
| 279 | .add_argument("disconnect <server-name>") | ||
| 280 | .add_argument("reconnect <server-name>") | ||
| 281 | .add_argument("help <matrix-command> [<matrix-subcommand>]") | ||
| 282 | .arguments_description( | ||
| 283 | " server: List, add, or remove Matrix servers. | ||
| 284 | connect: Connect to Matrix servers. | ||
| 285 | disconnect: Disconnect from one or all Matrix servers. | ||
| 286 | reconnect: Reconnect to server(s). | ||
| 287 | help: Show detailed command help.\n | ||
| 288 | Use /matrix [command] help to find out more.\n", | ||
| 289 | ) | ||
| 290 | .add_completion("server |add|delete|list|listfull") | ||
| 291 | .add_completion("connect") | ||
| 292 | .add_completion("disconnect") | ||
| 293 | .add_completion("reconnect") | ||
| 294 | .add_completion("help server|connect|disconnect|reconnect"); | ||
| 295 | |||
| 296 | let matrix = Command::new( | ||
| 297 | matrix_settings, | ||
| 298 | MatrixCommand { | ||
| 299 | servers: servers.clone(), | ||
| 300 | config: config.clone(), | ||
| 301 | }, | ||
| 302 | )?; | ||
| 303 | |||
| 304 | Ok(Commands { _matrix: matrix }) | ||
| 305 | } | 309 | } |
| 306 | } | 310 | } |