Init command for the validator

This commit is contained in:
Jedrzej Stuczynski
2020-02-05 15:52:35 +00:00
parent 83e22dbad9
commit 8ea9b14e94
2 changed files with 46 additions and 9 deletions
+38
View File
@@ -0,0 +1,38 @@
use crate::commands::override_config;
use clap::{App, Arg, ArgMatches};
use config::NymConfig;
pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> {
App::new("init")
.about("Initialise the validator")
.arg(
Arg::with_name("id")
.long("id")
.help("Id of the nym-mixnode we want to create config for.")
.takes_value(true)
.required(true),
)
.arg(
Arg::with_name("directory")
.long("directory")
.help("Address of the directory server the validator is sending presence to")
.takes_value(true),
)
}
pub fn execute(matches: &ArgMatches) {
let id = matches.value_of("id").unwrap();
println!("Initialising validator {}...", id);
let mut config = crate::config::Config::new(id);
config = override_config(config, matches);
let config_save_location = config.get_config_file_save_location();
config
.save_to_file(None)
.expect("Failed to save the config file");
println!("Saved configuration file to {:?}", config_save_location);
println!("Validator configuration completed.\n\n\n")
}
+8 -9
View File
@@ -2,10 +2,11 @@ use crate::validator::Config;
use crate::validator::Validator;
use clap::{App, Arg, ArgMatches, SubCommand};
use log::*;
use std::process;
use toml;
pub mod built_info;
mod commands;
mod config;
mod network;
mod services;
mod validator;
@@ -18,6 +19,7 @@ fn main() {
.version(built_info::PKG_VERSION)
.author("Nymtech")
.about("Implementation of Nym Validator")
.subcommand(commands::init::command_args())
.subcommand(
SubCommand::with_name("run")
.about("Starts the validator")
@@ -31,10 +33,7 @@ fn main() {
)
.get_matches();
if let Err(e) = execute(arg_matches) {
error!("{:?}", e);
process::exit(1);
}
execute(arg_matches);
}
fn run(matches: &ArgMatches) {
@@ -52,11 +51,11 @@ fn parse_config(matches: &ArgMatches) -> Config {
toml::from_str(&config_content).unwrap()
}
fn execute(matches: ArgMatches) -> Result<(), String> {
fn execute(matches: ArgMatches) {
match matches.subcommand() {
("run", Some(m)) => Ok(run(m)),
_ => Err(usage()),
("init", Some(m)) => commands::init::execute(m),
("run", Some(m)) => run(m),
_ => println!("{}", usage()),
}
}