commands: grouping into a subdirectory and cleaning up execution

This commit is contained in:
Dave Hrycyszyn
2019-12-11 00:57:01 +00:00
parent 1b70bd4d5a
commit 372d21f44e
5 changed files with 17 additions and 17 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
use clap::ArgMatches;
pub fn init(matches: &ArgMatches) {
pub fn execute(matches: &ArgMatches) {
println!("Running client init!");
// don't unwrap it, pass it as it is, if it's None, choose a random
+3
View File
@@ -0,0 +1,3 @@
pub mod init;
pub mod run;
pub mod socket;
+1 -1
View File
@@ -9,7 +9,7 @@ use std::time::Duration;
use tokio::runtime::Runtime;
use tokio::time::{interval_at, Instant};
pub fn run(matches: &ArgMatches) {
pub fn execute(matches: &ArgMatches) {
let custom_cfg = matches.value_of("customCfg");
println!(
"Going to start client with custom config of: {:?}",
+1 -1
View File
@@ -1,6 +1,6 @@
use clap::ArgMatches;
pub fn socket(matches: &ArgMatches) {
pub fn execute(matches: &ArgMatches) {
let custom_cfg = matches.value_of("customCfg");
let socket_type = match matches.value_of("socketType").unwrap() {
TCP_SOCKET_TYPE => TCP_SOCKET_TYPE,
+11 -14
View File
@@ -2,24 +2,11 @@ use clap::{App, Arg, ArgMatches, SubCommand};
use std::process;
mod clients;
mod init;
mod run;
mod socket;
mod commands;
const TCP_SOCKET_TYPE: &str = "tcp";
const WEBSOCKET_SOCKET_TYPE: &str = "websocket";
fn execute(matches: ArgMatches) -> Result<(), String> {
match matches.subcommand() {
("init", Some(m)) => Ok(init::init(m)),
("run", Some(m)) => Ok(run::run(m)),
("socket", Some(m)) => Ok(socket::socket(m)),
_ => Err(String::from("Unknown command")),
}
}
// TODO: perhaps more subcommands and/or args to distinguish between coco client and mix client
fn main() {
let arg_matches = App::new("Nym Client")
.version("0.1.0")
@@ -85,3 +72,13 @@ fn main() {
process::exit(1);
}
}
fn execute(matches: ArgMatches) -> Result<(), String> {
match matches.subcommand() {
("init", Some(m)) => Ok(commands::init::execute(m)),
("run", Some(m)) => Ok(commands::run::execute(m)),
("socket", Some(m)) => Ok(commands::socket::execute(m)),
_ => Err(String::from("Unknown command")),
}
}