-
Notifications
You must be signed in to change notification settings - Fork 39
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 #2012 from input-output-hk/djo/refactor_client_cli…
…_command_params Refactor client cli command parameters
- Loading branch information
Showing
21 changed files
with
326 additions
and
198 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,47 @@ | ||
use config::builder::DefaultState; | ||
use config::ConfigBuilder; | ||
use slog::Logger; | ||
use std::collections::HashMap; | ||
|
||
use mithril_client::MithrilResult; | ||
|
||
use crate::configuration::ConfigParameters; | ||
|
||
/// Context for the command execution | ||
pub struct CommandContext { | ||
config_builder: ConfigBuilder<DefaultState>, | ||
unstable_enabled: bool, | ||
logger: Logger, | ||
} | ||
|
||
impl CommandContext { | ||
/// Create a new command context | ||
pub fn new( | ||
config_builder: ConfigBuilder<DefaultState>, | ||
unstable_enabled: bool, | ||
logger: Logger, | ||
) -> Self { | ||
Self { | ||
config_builder, | ||
unstable_enabled, | ||
logger, | ||
} | ||
} | ||
|
||
/// Check if unstable commands are enabled | ||
pub fn is_unstable_enabled(&self) -> bool { | ||
self.unstable_enabled | ||
} | ||
|
||
/// Get the configured parameters | ||
pub fn config_parameters(&self) -> MithrilResult<ConfigParameters> { | ||
let config = self.config_builder.clone().build()?; | ||
let config_hash_map = config.try_deserialize::<HashMap<String, String>>()?; | ||
Ok(ConfigParameters::new(config_hash_map)) | ||
} | ||
|
||
/// Get the shared logger | ||
pub fn logger(&self) -> &Logger { | ||
&self.logger | ||
} | ||
} |
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
Oops, something went wrong.