-
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.
Merge pull request #14 from iqlusioninc/application-lifecycle
Full application lifecycle implementation
- Loading branch information
Showing
15 changed files
with
192 additions
and
114 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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use std::path::PathBuf; | ||
|
||
use config::GlobalConfig; | ||
use error::FrameworkError; | ||
use util::{CanonicalPath, CanonicalPathBuf}; | ||
|
||
/// Support for loading configuration from a file. | ||
/// Does not modify the global configuration. Only handles parsing and | ||
/// deserializing it from files. | ||
pub trait LoadConfig<C: GlobalConfig> { | ||
/// Path to the command's configuration file. Returns an error by default. | ||
fn config_path(&self) -> Option<PathBuf> { | ||
None | ||
} | ||
|
||
/// Load the configuration from `self.config_path()` if present | ||
fn load_global_config(&self) -> Result<(), FrameworkError> { | ||
// Only attempt to load configuration if `config_path` returned the | ||
// path to a configuration file. | ||
if let Some(path) = self.config_path() { | ||
let canonical_path = CanonicalPathBuf::canonicalize(path)?; | ||
let config = self.load_config_file(&canonical_path)?; | ||
C::set_global(config); | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
/// Load the configuration for this command | ||
fn load_config_file<P: AsRef<CanonicalPath>>(&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> { | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
//! Support for managing global configuration, as well as loading it from TOML | ||
mod global; | ||
#[cfg(feature = "options")] | ||
mod options; | ||
mod load; | ||
mod reader; | ||
|
||
pub use self::global::GlobalConfig; | ||
#[cfg(feature = "options")] | ||
pub use self::options::MergeOptions; | ||
pub use self::load::LoadConfig; | ||
pub use self::reader::ConfigReader; |
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
Oops, something went wrong.