Skip to content

Commit b6fb6c2

Browse files
authored
Merge pull request #2630 from input-output-hk/ctl/2620-add-client-CLI-version-in-stderr
Add print in output of the client CLI version at each command execution
2 parents 6833d2f + 0bbd891 commit b6fb6c2

File tree

23 files changed

+423
-376
lines changed

23 files changed

+423
-376
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/website/root/manual/develop/nodes/mithril-client.md

Lines changed: 157 additions & 44 deletions
Large diffs are not rendered by default.

mithril-client-cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-client-cli"
3-
version = "0.12.19"
3+
version = "0.12.20"
44
description = "A Mithril Client"
55
authors = { workspace = true }
66
edition = { workspace = true }

mithril-client-cli/src/command_context.rs

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
use anyhow::anyhow;
2-
use config::ConfigBuilder;
3-
use config::builder::DefaultState;
42
use slog::Logger;
5-
use std::collections::HashMap;
63

74
use mithril_client::MithrilResult;
85

96
use crate::configuration::ConfigParameters;
107

118
/// Context for the command execution
129
pub struct CommandContext {
13-
config_builder: ConfigBuilder<DefaultState>,
10+
config_parameters: ConfigParameters,
1411
unstable_enabled: bool,
12+
json: bool,
1513
logger: Logger,
1614
}
1715

1816
impl CommandContext {
1917
/// Create a new command context
2018
pub fn new(
21-
config_builder: ConfigBuilder<DefaultState>,
19+
config_parameters: ConfigParameters,
2220
unstable_enabled: bool,
21+
json: bool,
2322
logger: Logger,
2423
) -> Self {
2524
Self {
26-
config_builder,
25+
config_parameters,
2726
unstable_enabled,
27+
json,
2828
logger,
2929
}
3030
}
@@ -34,6 +34,11 @@ impl CommandContext {
3434
self.unstable_enabled
3535
}
3636

37+
/// Check if JSON output is enabled
38+
pub fn is_json_output_enabled(&self) -> bool {
39+
self.json
40+
}
41+
3742
/// Ensure that unstable commands are enabled
3843
pub fn require_unstable(
3944
&self,
@@ -51,11 +56,14 @@ impl CommandContext {
5156
}
5257
}
5358

54-
/// Get the configured parameters
55-
pub fn config_parameters(&self) -> MithrilResult<ConfigParameters> {
56-
let config = self.config_builder.clone().build()?;
57-
let config_hash_map = config.try_deserialize::<HashMap<String, String>>()?;
58-
Ok(ConfigParameters::new(config_hash_map))
59+
/// Get a reference to the configured parameters
60+
pub fn config_parameters(&self) -> &ConfigParameters {
61+
&self.config_parameters
62+
}
63+
64+
/// Get a mutable reference to the configured parameters
65+
pub fn config_parameters_mut(&mut self) -> &mut ConfigParameters {
66+
&mut self.config_parameters
5967
}
6068

6169
/// Get the shared logger
@@ -67,15 +75,19 @@ impl CommandContext {
6775
#[cfg(test)]
6876
mod tests {
6977
use slog::o;
78+
use std::collections::HashMap;
79+
80+
use crate::configuration::{ConfigError, ConfigSource};
7081

7182
use super::*;
7283

7384
#[test]
7485
fn require_unstable_return_ok_if_unstable_enabled() {
7586
let unstable_enabled = true;
7687
let context = CommandContext::new(
77-
ConfigBuilder::default(),
88+
ConfigParameters::default(),
7889
unstable_enabled,
90+
true,
7991
Logger::root(slog::Discard, o!()),
8092
);
8193

@@ -87,12 +99,48 @@ mod tests {
8799
fn require_unstable_return_err_if_unstable_disabled() {
88100
let unstable_enabled = false;
89101
let context = CommandContext::new(
90-
ConfigBuilder::default(),
102+
ConfigParameters::default(),
91103
unstable_enabled,
104+
true,
92105
Logger::root(slog::Discard, o!()),
93106
);
94107

95108
let result = context.require_unstable("test", None);
96109
assert!(result.is_err(), "Expected Err, got {result:?}");
97110
}
111+
112+
#[test]
113+
fn can_edit_config_parameters() {
114+
struct ParamSource {
115+
key: String,
116+
value: String,
117+
}
118+
impl ConfigSource for ParamSource {
119+
fn collect(&self) -> Result<HashMap<String, String>, ConfigError> {
120+
Ok(HashMap::from([(self.key.clone(), self.value.clone())]))
121+
}
122+
}
123+
124+
let mut context = CommandContext::new(
125+
ConfigParameters::default(),
126+
false,
127+
true,
128+
Logger::root(slog::Discard, o!()),
129+
);
130+
131+
assert_eq!(context.config_parameters_mut().get("key"), None,);
132+
133+
context
134+
.config_parameters_mut()
135+
.add_source(&ParamSource {
136+
key: "key".to_string(),
137+
value: "value".to_string(),
138+
})
139+
.unwrap();
140+
141+
assert_eq!(
142+
context.config_parameters_mut().get("key"),
143+
Some("value".to_string())
144+
);
145+
}
98146
}

0 commit comments

Comments
 (0)