Skip to content

Commit

Permalink
Improve config loading message (#933)
Browse files Browse the repository at this point in the history
* Improve config load message

* Raised log level to error. Log link to config example in the guide.

* Changelog

Co-authored-by: Adi Seredinschi <adi@informal.systems>
  • Loading branch information
2 people authored and ancazamfir committed May 26, 2021
1 parent 14ebcc4 commit 2d2a5dd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
- [ibc]
- Started `unwrap` cleanup ([#871])

- [ibc-relayer-cli]
- Improve config loading message ([#996])

### BUG FIXES

- [ibc-relayer]
Expand All @@ -28,6 +31,7 @@
[#911]: https://github.com/informalsystems/ibc-rs/issues/911
[#972]: https://github.com/informalsystems/ibc-rs/issues/972
[#983]: https://github.com/informalsystems/ibc-rs/issues/983
[#996]: https://github.com/informalsystems/ibc-rs/issues/996

## v0.3.2
*May 21st, 2021*
Expand Down
30 changes: 26 additions & 4 deletions relayer-cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::path::PathBuf;
use abscissa_core::{
config::Override, Command, Configurable, FrameworkError, Help, Options, Runnable,
};
use tracing::info;
use tracing::{error, info};

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 @@ -96,9 +95,32 @@ pub enum CliCmd {
/// This trait allows you to define how application configuration is loaded.
impl Configurable<Config> for CliCmd {
/// Location of the configuration file
/// This is called only when the `-c` command-line option is omitted.
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) => {
// No file exists at the config path
error!("could not find configuration file at '{}'", path.display());
error!("for an example, please see https://hermes.informal.systems/config.html#example-configuration-file");
None
}
None => {
// The path to the default config file could not be found
error!("could not find default configuration file");
error!(
"please create one at '~/{}' or specify it with the '-c'/'--config' flag",
DEFAULT_CONFIG_PATH
);
error!("for an example, please see https://hermes.informal.systems/config.html#example-configuration-file");
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 2d2a5dd

Please sign in to comment.