Load config file from CLI flag (#2333)

Fixes #2317 in the least intrusive way. I believe that given a slightly more
rigorous refactor could improve the readability quite a bit. Will suggest a
follow up PR.
This commit is contained in:
Harm Aarts 2019-01-12 00:54:24 +01:00 committed by Ignotus Peverell
parent 6ea95cd764
commit cf8f9d609a

View file

@ -114,6 +114,7 @@ fn real_main() -> i32 {
_ => {} _ => {}
} }
// Load relevant config
match args.subcommand() { match args.subcommand() {
// If it's a wallet command, try and load a wallet config file // If it's a wallet command, try and load a wallet config file
("wallet", Some(wallet_args)) => { ("wallet", Some(wallet_args)) => {
@ -136,33 +137,54 @@ fn real_main() -> i32 {
); );
wallet_config = Some(w); wallet_config = Some(w);
} }
// When the subscommand is 'server' take into account the 'config_file' flag
("server", Some(server_args)) => {
if let Some(_path) = server_args.value_of("config_file") {
node_config = Some(config::GlobalConfig::new(_path).unwrap_or_else(|e| {
panic!("Error loading server configuration: {}", e);
}));
} else {
node_config = Some(
config::initial_setup_server(&chain_type).unwrap_or_else(|e| {
panic!("Error loading server configuration: {}", e);
}),
);
}
}
// Otherwise load up the node config as usual // Otherwise load up the node config as usual
_ => { _ => {
let mut s = config::initial_setup_server(&chain_type).unwrap_or_else(|e| { node_config = Some(
panic!("Error loading server configuration: {}", e); config::initial_setup_server(&chain_type).unwrap_or_else(|e| {
}); panic!("Error loading server configuration: {}", e);
let mut l = s.members.as_mut().unwrap().logging.clone().unwrap(); }),
let run_tui = s.members.as_mut().unwrap().server.run_tui; );
if let Some(true) = run_tui { }
l.log_to_stdout = false; }
l.tui_running = Some(true);
} if let Some(mut config) = node_config.clone() {
init_logger(Some(l)); let mut l = config.members.as_mut().unwrap().logging.clone().unwrap();
global::set_mining_mode(s.members.as_mut().unwrap().server.clone().chain_type); let run_tui = config.members.as_mut().unwrap().server.run_tui;
if let Some(file_path) = &s.config_file_path { if let Some(true) = run_tui {
info!( l.log_to_stdout = false;
"Using configuration file at {}", l.tui_running = Some(true);
file_path.to_str().unwrap() }
); init_logger(Some(l));
} else {
info!("Node configuration file not found, using default"); global::set_mining_mode(config.members.unwrap().server.clone().chain_type);
}
node_config = Some(s); if let Some(file_path) = &config.config_file_path {
info!(
"Using configuration file at {}",
file_path.to_str().unwrap()
);
} else {
info!("Node configuration file not found, using default");
} }
} }
log_build_info(); log_build_info();
// Execute subcommand
match args.subcommand() { match args.subcommand() {
// server commands and options // server commands and options
("server", Some(server_args)) => { ("server", Some(server_args)) => {