Skip to content

Commit e79b500

Browse files
committed
feature(client-cli): add print of the version at each command execution
1 parent caff9bf commit e79b500

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

mithril-client-cli/src/main.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,7 @@ pub struct Args {
9595

9696
impl Args {
9797
pub async fn execute(&self, root_logger: Logger) -> MithrilResult<()> {
98-
debug!(
99-
root_logger,
100-
"Mithril client CLI version: {}",
101-
env!("CARGO_PKG_VERSION")
102-
);
98+
self.print_and_log_version(&root_logger);
10399
debug!(root_logger, "Run Mode: {}", self.run_mode);
104100

105101
let config_parameters = self.config_parameters(&root_logger)?;
@@ -108,6 +104,19 @@ impl Args {
108104
self.command.execute(context).await
109105
}
110106

107+
fn print_and_log_version(&self, root_logger: &Logger) {
108+
let client_cli_version = env!("CARGO_PKG_VERSION");
109+
let version_message = format!("Mithril Client CLI version: {client_cli_version}");
110+
if self.json {
111+
let json_message = serde_json::json!({
112+
"mithril_client_cli_version": client_cli_version});
113+
eprintln!("{json_message}");
114+
} else {
115+
eprintln!("{version_message}");
116+
}
117+
debug!(root_logger, "{version_message}");
118+
}
119+
111120
fn log_level(&self) -> Level {
112121
match self.verbose {
113122
0 => Level::Error,

0 commit comments

Comments
 (0)