From 2b86a7864b8ae37a812bb9ea4c2c346ed3858078 Mon Sep 17 00:00:00 2001 From: Alexey Proshutinskiy Date: Wed, 27 Oct 2021 23:25:15 +0300 Subject: [PATCH 1/2] load config from default path if cmd arg not provided --- 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..da96532796 100644 --- a/crates/server-config/src/resolved_config.rs +++ b/crates/server-config/src/resolved_config.rs @@ -20,6 +20,7 @@ use crate::ListenConfig; use fs_utils::to_abs_path; +use crate::defaults::default_config_path; use clap::{ArgMatches, Values}; use eyre::{eyre, WrapErr}; use libp2p::core::{multiaddr::Protocol, Multiaddr}; @@ -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); From 09a130df0466839d521c7af963b182bb0f7028b7 Mon Sep 17 00:00:00 2001 From: Alexey Proshutinskiy Date: Wed, 27 Oct 2021 23:26:05 +0300 Subject: [PATCH 2/2] sort imports properly --- crates/server-config/src/resolved_config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/server-config/src/resolved_config.rs b/crates/server-config/src/resolved_config.rs index da96532796..63749328df 100644 --- a/crates/server-config/src/resolved_config.rs +++ b/crates/server-config/src/resolved_config.rs @@ -14,13 +14,13 @@ * limitations under the License. */ +use crate::defaults::default_config_path; use crate::dir_config::{ResolvedDirConfig, UnresolvedDirConfig}; use crate::node_config::NodeConfig; use crate::ListenConfig; use fs_utils::to_abs_path; -use crate::defaults::default_config_path; use clap::{ArgMatches, Values}; use eyre::{eyre, WrapErr}; use libp2p::core::{multiaddr::Protocol, Multiaddr};