Commit 202dc75836

202dc7583624e5163a1a39b4c082533bb6384e83

parent: 28a334fe70

Unsigned

Damir Jelić <poljar@termina.org.uk> · 2020-07-22 17:31 UTC

commands: Move the matrix command creation into a separate method.

Layout: unified · split

src/commands/mod.rs +35 −31
@@ -20,6 +20,38 @@ struct MatrixCommand {
2020}
2121
2222impl 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
38Use /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
2355 fn add_server(&self, args: &ArgMatches) {
2456 let server_name = args
2557 .value_of("name")
@@ -271,36 +303,8 @@ impl Commands {
271303 servers: &Servers,
272304 config: &ConfigHandle,
273305 ) -> Result<Commands, ()> {
274 let matrix_settings = CommandSettings::new("matrix")
275 .description("Matrix chat protocol command.")
276 .add_argument("server add <server-name> <hostname>[:<port>]")
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
288Use /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 })
306 Ok(Commands {
307 _matrix: MatrixCommand::new(servers, config)?,
308 })
305309 }
306310}