Skip to content

Commit

Permalink
Improve config load message
Browse files Browse the repository at this point in the history
  • Loading branch information
romac committed May 12, 2021
1 parent c2d5c58 commit 4359cad
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
25 changes: 21 additions & 4 deletions relayer-cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use std::path::PathBuf;

use abscissa_core::{Command, Configurable, FrameworkError, Help, Options, Runnable};
use tracing::info;
use tracing::{info, warn};

use crate::config::Config;
use crate::DEFAULT_CONFIG_PATH;
Expand All @@ -35,7 +35,6 @@ mod version;

/// Default configuration file path
pub fn default_config_file() -> Option<PathBuf> {
info!("Using default configuration from: '.hermes/config.toml'");
dirs_next::home_dir().map(|home| home.join(DEFAULT_CONFIG_PATH))
}

Expand Down Expand Up @@ -101,8 +100,26 @@ pub enum CliCmd {
impl Configurable<Config> for CliCmd {
/// Location of the configuration file
fn config_path(&self) -> Option<PathBuf> {
let filename = default_config_file();
filename.filter(|f| f.exists())
let path = default_config_file();

match path {
Some(path) if path.exists() => {
info!("using default configuration from '{}'", path.display());
Some(path)
}
Some(path) => {
warn!("could not find configuration file at '{}'", path.display());
None
}
None => {
warn!("could not find default configuration file");
warn!(
"please create one at '~/{}' or specify it with the --config flag",
DEFAULT_CONFIG_PATH
);
None
}
}
}

/// Apply changes to the config after it's been loaded, e.g. overriding
Expand Down
2 changes: 1 addition & 1 deletion relayer-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ pub(crate) mod components;
pub(crate) mod conclude;
pub(crate) mod entry;

/// The path to the default configuration file.
/// The path to the default configuration file, relative to the home directory.
pub const DEFAULT_CONFIG_PATH: &str = ".hermes/config.toml";

0 comments on commit 4359cad

Please sign in to comment.