Moved args definition to specific commands file

This commit is contained in:
Jedrzej Stuczynski
2020-02-03 13:07:45 +00:00
parent ac5d16899e
commit c7c52e68b5
3 changed files with 75 additions and 71 deletions
+33 -1
View File
@@ -1,7 +1,7 @@
use crate::built_info;
use crate::commands::override_config;
use crate::config::persistance::pathfinder::ClientPathfinder;
use clap::ArgMatches;
use clap::{App, Arg, ArgMatches};
use config::NymConfig;
use crypto::identity::MixIdentityKeyPair;
use directory_client::presence::Topology;
@@ -11,6 +11,38 @@ use sphinx::route::DestinationAddressBytes;
use topology::provider::Node;
use topology::NymTopology;
pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> {
App::new("init")
.about("Initialise a Nym client. Do this first!")
.arg(Arg::with_name("id")
.long("id")
.help("Id of the nym-mixnet-client we want to create config for.")
.takes_value(true)
.required(true)
)
.arg(Arg::with_name("provider")
.long("provider")
.help("Id of the provider we have preference to connect to. If left empty, a random provider will be chosen.")
.takes_value(true)
)
.arg(Arg::with_name("directory")
.long("directory")
.help("Address of the directory server the client is getting topology from")
.takes_value(true),
)
.arg(Arg::with_name("socket-type")
.long("socket-type")
.help("Type of socket to use (TCP, WebSocket or None) in all subsequent runs")
.takes_value(true)
)
.arg(Arg::with_name("port")
.short("p")
.long("port")
.help("Port for the socket (if applicable) to listen on in all subsequent runs")
.takes_value(true)
)
}
async fn try_provider_registrations(
providers: Vec<Node>,
our_address: DestinationAddressBytes,
+39 -1
View File
@@ -2,10 +2,48 @@ use crate::client::NymClient;
use crate::commands::override_config;
use crate::config::persistance::pathfinder::ClientPathfinder;
use crate::config::Config;
use clap::ArgMatches;
use clap::{App, Arg, ArgMatches};
use config::NymConfig;
use pemstore::pemstore::PemStore;
pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> {
App::new("run")
.about("Run the Nym client with provided configuration client optionally overriding set parameters")
.arg(Arg::with_name("id")
.long("id")
.help("Id of the nym-mixnet-client we want to run.")
.takes_value(true)
.required(true)
)
// the rest of arguments are optional, they are used to override settings in config file
.arg(Arg::with_name("config")
.long("config")
.help("Custom path to the nym-mixnet-client configuration file")
.takes_value(true)
)
.arg(Arg::with_name("directory")
.long("directory")
.help("Address of the directory server the client is getting topology from")
.takes_value(true),
)
.arg(Arg::with_name("provider")
.long("provider")
.help("Id of the provider we want to connect to. If overridden, it is user's responsibility to ensure prior registration happened")
.takes_value(true)
)
.arg(Arg::with_name("socket-type")
.long("socket-type")
.help("Type of socket to use (TCP, WebSocket or None)")
.takes_value(true)
)
.arg(Arg::with_name("port")
.short("p")
.long("port")
.help("Port for the socket (if applicable) to listen on")
.takes_value(true)
)
}
pub fn execute(matches: &ArgMatches) {
let id = matches.value_of("id").unwrap();
+3 -69
View File
@@ -1,4 +1,4 @@
use clap::{App, Arg, ArgMatches, SubCommand};
use clap::{App, ArgMatches};
pub mod built_info;
pub mod client;
@@ -14,74 +14,8 @@ fn main() {
.version(built_info::PKG_VERSION)
.author("Nymtech")
.about("Implementation of the Nym Client")
.subcommand(
SubCommand::with_name("init")
.about("Initialise a Nym client. Do this first!")
.arg(Arg::with_name("id")
.long("id")
.help("Id of the nym-mixnet-client we want to create config for.")
.takes_value(true)
.required(true)
)
.arg(Arg::with_name("provider")
.long("provider")
.help("Id of the provider we have preference to connect to. If left empty, a random provider will be chosen.")
.takes_value(true)
)
.arg(Arg::with_name("directory")
.long("directory")
.help("Address of the directory server the client is getting topology from")
.takes_value(true),
)
.arg(Arg::with_name("socket-type")
.long("socket-type")
.help("Type of socket to use (TCP, WebSocket or None) in all subsequent runs")
.takes_value(true)
)
.arg(Arg::with_name("port")
.short("p")
.long("port")
.help("Port for the socket (if applicable) to listen on in all subsequent runs")
.takes_value(true)
)
)
.subcommand(
SubCommand::with_name("run")
.about("Run the Nym client with provided configuration client optionally overriding set parameters")
.arg(Arg::with_name("id")
.long("id")
.help("Id of the nym-mixnet-client we want to run.")
.takes_value(true)
.required(true)
)
// the rest of arguments are optional, they are used to override settings in config file
.arg(Arg::with_name("config")
.long("config")
.help("Custom path to the nym-mixnet-client configuration file")
.takes_value(true)
)
.arg(Arg::with_name("directory")
.long("directory")
.help("Address of the directory server the client is getting topology from")
.takes_value(true),
)
.arg(Arg::with_name("provider")
.long("provider")
.help("Id of the provider we want to connect to. If overridden, it is user's responsibility to ensure prior registration happened")
.takes_value(true)
)
.arg(Arg::with_name("socket-type")
.long("socket-type")
.help("Type of socket to use (TCP, WebSocket or None)")
.takes_value(true)
)
.arg(Arg::with_name("port")
.short("p")
.long("port")
.help("Port for the socket (if applicable) to listen on")
.takes_value(true)
)
)
.subcommand(commands::init::command_args())
.subcommand(commands::run::command_args())
.get_matches();
execute(arg_matches);