-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] Configuration loading improvements (fixes #79)
- Have `command::EntryPoint` delegate its `Configurable` impl to the command it wraps. - Simplify configuration loading logic in `Application`. - Rename `config::MergeOptions` to `config::Override` and provide an example of how to use it in the boilerplate.
- Loading branch information
1 parent
626874b
commit 77dc56d
Showing
7 changed files
with
87 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,19 @@ | ||
//! Configuration loader | ||
use super::Config; | ||
use crate::{error::FrameworkError, path::AbsPath}; | ||
use crate::error::FrameworkError; | ||
use std::path::PathBuf; | ||
|
||
/// Command type with which a configuration file is associated | ||
pub trait Configurable<C: Config> { | ||
pub trait Configurable<Cfg: Config> { | ||
/// Path to the command's configuration file. Returns an error by default. | ||
fn config_path(&self) -> Option<PathBuf> { | ||
None | ||
} | ||
|
||
/// Load the configuration for this command | ||
fn load_config_file<P: AsRef<AbsPath>>(&self, path: &P) -> Result<C, FrameworkError> { | ||
self.preprocess_config(C::load_toml_file(path)?) | ||
} | ||
|
||
/// Process the configuration after it has been loaded, potentially | ||
/// modifying it or returning an error if options are incompatible | ||
#[allow(unused_mut)] | ||
fn preprocess_config(&self, mut config: C) -> Result<C, FrameworkError> { | ||
fn process_config(&self, config: Cfg) -> Result<Cfg, FrameworkError> { | ||
Ok(config) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters