Skip to content
This repository was archived by the owner on Feb 11, 2025. It is now read-only.

Commit 440a62b

Browse files
authored
Merge pull request #242 from adamreese/feat/info-format
feat(client): add json output to bindle info
2 parents 155aeae + 66b1a20 commit 440a62b

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

bin/client/main.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,21 @@ async fn run() -> std::result::Result<(), ClientError> {
144144
}
145145
.await
146146
.map_err(map_storage_error)?;
147-
tokio::io::stdout().write_all(&toml::to_vec(&inv)?).await?;
147+
148+
match info_opts.output {
149+
Some(format) if &format == "toml" => {
150+
tokio::io::stdout().write_all(&toml::to_vec(&inv)?).await?
151+
}
152+
Some(format) if &format == "json" => {
153+
tokio::io::stdout()
154+
.write_all(&serde_json::to_vec_pretty(&inv)?)
155+
.await?
156+
}
157+
Some(format) => {
158+
return Err(ClientError::Other(format!("Unknown format: {}", format)))
159+
}
160+
None => tokio::io::stdout().write_all(&toml::to_vec(&inv)?).await?,
161+
}
148162
}
149163
SubCommand::GetInvoice(gi_opts) => {
150164
let inv = match gi_opts.yanked {

bin/client/opts.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,13 @@ pub struct Info {
136136
about = "Whether or not to fetch a yanked bindle. If you attempt to fetch a yanked bindle without this set, it will error"
137137
)]
138138
pub yanked: bool,
139+
#[clap(
140+
short = 'f',
141+
long = "output-format",
142+
about = "choose an output format",
143+
possible_values = &["json", "toml"],
144+
)]
145+
pub output: Option<String>,
139146
}
140147

141148
#[derive(Clap)]

0 commit comments

Comments
 (0)