Skip to content

Commit acd32fd

Browse files
committed
Output warning in JSON format when option --json is set
1 parent d3064e6 commit acd32fd

File tree

5 files changed

+30
-1
lines changed

5 files changed

+30
-1
lines changed

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)