From 7b7049c7fdc6cb69933559725d2bb8f9144ff8a7 Mon Sep 17 00:00:00 2001 From: Aleksey Proshutisnkiy Date: Thu, 28 Oct 2021 13:05:28 +0300 Subject: [PATCH] Load config from default path if cmd arg is not provided (#1204) --- crates/server-config/src/defaults.rs | 4 ++++ crates/server-config/src/resolved_config.rs | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/server-config/src/defaults.rs b/crates/server-config/src/defaults.rs index 301b807b11..2fbbdbe27e 100644 --- a/crates/server-config/src/defaults.rs +++ b/crates/server-config/src/defaults.rs @@ -26,6 +26,10 @@ use std::time::Duration; const CONFIG_VERSION: usize = 1; +pub fn default_config_path() -> PathBuf { + default_base_dir().join("Config.toml") +} + pub fn default_tcp_port() -> u16 { 7777 } diff --git a/crates/server-config/src/resolved_config.rs b/crates/server-config/src/resolved_config.rs index f349a030ef..63749328df 100644 --- a/crates/server-config/src/resolved_config.rs +++ b/crates/server-config/src/resolved_config.rs @@ -14,6 +14,7 @@ * limitations under the License. */ +use crate::defaults::default_config_path; use crate::dir_config::{ResolvedDirConfig, UnresolvedDirConfig}; use crate::node_config::NodeConfig; use crate::ListenConfig; @@ -237,8 +238,9 @@ fn insert_args_to_config( // TODO: avoid depending on ArgMatches pub fn load_config(arguments: ArgMatches) -> eyre::Result { let config_file = arguments.value_of(CONFIG_FILE).map(Into::into); + let config_file = config_file.unwrap_or(default_config_path()); - let config_bytes = if let Some(config_file) = config_file { + let config_bytes = if config_file.is_file() { let config_file = to_abs_path(config_file); log::info!("Loading config from {:?}", config_file);