mirror of
https://github.com/mimblewimble/grin.git
synced 2025-02-01 17:01:09 +03:00
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:
parent
6ea95cd764
commit
cf8f9d609a
1 changed files with 42 additions and 20 deletions
|
@ -114,6 +114,7 @@ fn real_main() -> i32 {
|
|||
_ => {}
|
||||
}
|
||||
|
||||
// Load relevant config
|
||||
match args.subcommand() {
|
||||
// If it's a wallet command, try and load a wallet config file
|
||||
("wallet", Some(wallet_args)) => {
|
||||
|
@ -136,33 +137,54 @@ fn real_main() -> i32 {
|
|||
);
|
||||
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
|
||||
_ => {
|
||||
let mut s = 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);
|
||||
}
|
||||
init_logger(Some(l));
|
||||
global::set_mining_mode(s.members.as_mut().unwrap().server.clone().chain_type);
|
||||
if let Some(file_path) = &s.config_file_path {
|
||||
info!(
|
||||
"Using configuration file at {}",
|
||||
file_path.to_str().unwrap()
|
||||
);
|
||||
} else {
|
||||
info!("Node configuration file not found, using default");
|
||||
}
|
||||
node_config = Some(s);
|
||||
node_config = Some(
|
||||
config::initial_setup_server(&chain_type).unwrap_or_else(|e| {
|
||||
panic!("Error loading server configuration: {}", e);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(mut config) = node_config.clone() {
|
||||
let mut l = config.members.as_mut().unwrap().logging.clone().unwrap();
|
||||
let run_tui = config.members.as_mut().unwrap().server.run_tui;
|
||||
if let Some(true) = run_tui {
|
||||
l.log_to_stdout = false;
|
||||
l.tui_running = Some(true);
|
||||
}
|
||||
init_logger(Some(l));
|
||||
|
||||
global::set_mining_mode(config.members.unwrap().server.clone().chain_type);
|
||||
|
||||
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();
|
||||
|
||||
// Execute subcommand
|
||||
match args.subcommand() {
|
||||
// server commands and options
|
||||
("server", Some(server_args)) => {
|
||||
|
|
Loading…
Reference in a new issue