Skip to content

Commit 8725527

Browse files
authored
Merge pull request #1631 from input-output-hk/sfa/1616-write-deprecation-notice-in-json
fix: Output deprecation warning in JSON format when option --json is set
2 parents d3064e6 + f3c0469 commit 8725527

File tree

7 files changed

+32
-3
lines changed

7 files changed

+32
-3
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.

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.7.9"
3+
version = "0.7.10"
44
description = "A Mithril Client"
55
authors = { workspace = true }
66
edition = { workspace = true }

mithril-client-cli/src/commands/cardano_db/download.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ pub struct CardanoDbDownloadCommand {
4646
}
4747

4848
impl CardanoDbDownloadCommand {
49+
/// Is JSON output enabled
50+
pub fn is_json_output_enabled(&self) -> bool {
51+
self.json
52+
}
53+
4954
/// Command execution
5055
pub async fn execute(&self, config_builder: ConfigBuilder<DefaultState>) -> MithrilResult<()> {
5156
let config = config_builder.add_source(self.clone()).build()?;

mithril-client-cli/src/commands/cardano_db/list.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ pub struct CardanoDbListCommand {
1515
}
1616

1717
impl CardanoDbListCommand {
18+
/// Is JSON output enabled
19+
pub fn is_json_output_enabled(&self) -> bool {
20+
self.json
21+
}
22+
1823
/// Main command execution
1924
pub async fn execute(&self, config_builder: ConfigBuilder<DefaultState>) -> MithrilResult<()> {
2025
let config = config_builder.build()?;

mithril-client-cli/src/commands/cardano_db/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,14 @@ pub mod deprecated {
8787
Self::Show(cmd) => cmd.execute(config_builder).await,
8888
}
8989
}
90+
91+
/// Is JSON output enabled
92+
pub fn is_json_output_enabled(&self) -> bool {
93+
match self {
94+
Self::List(cmd) => cmd.is_json_output_enabled(),
95+
Self::Download(cmd) => cmd.is_json_output_enabled(),
96+
Self::Show(cmd) => cmd.is_json_output_enabled(),
97+
}
98+
}
9099
}
91100
}

mithril-client-cli/src/commands/cardano_db/show.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ pub struct CardanoDbShowCommand {
2424
}
2525

2626
impl CardanoDbShowCommand {
27+
/// Is JSON output enabled
28+
pub fn is_json_output_enabled(&self) -> bool {
29+
self.json
30+
}
31+
2732
/// Cardano DB Show command
2833
pub async fn execute(&self, config_builder: ConfigBuilder<DefaultState>) -> MithrilResult<()> {
2934
let config = config_builder.build()?;

mithril-client-cli/src/main.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,12 @@ impl ArtifactCommands {
190190
match self {
191191
#[allow(deprecated)]
192192
Self::Snapshot(cmd) => {
193-
eprintln!("`snapshot` command is deprecated, use `cardano-db` instead");
193+
let message = "`snapshot` command is deprecated, use `cardano-db` instead";
194+
if cmd.is_json_output_enabled() {
195+
eprintln!(r#"{{"warning": "{}", "type": "deprecation"}}"#, message);
196+
} else {
197+
eprintln!("{}", message);
198+
};
194199
cmd.execute(config_builder).await
195200
}
196201
Self::CardanoDb(cmd) => cmd.execute(config_builder).await,

0 commit comments

Comments
 (0)