Skip to content

Commit

Permalink
Merge pull request #242 from adamreese/feat/info-format
Browse files Browse the repository at this point in the history
feat(client): add json output to bindle info
  • Loading branch information
adamreese committed Sep 20, 2021
2 parents 155aeae + 66b1a20 commit 440a62b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
16 changes: 15 additions & 1 deletion bin/client/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,21 @@ async fn run() -> std::result::Result<(), ClientError> {
}
.await
.map_err(map_storage_error)?;
tokio::io::stdout().write_all(&toml::to_vec(&inv)?).await?;

match info_opts.output {
Some(format) if &format == "toml" => {
tokio::io::stdout().write_all(&toml::to_vec(&inv)?).await?
}
Some(format) if &format == "json" => {
tokio::io::stdout()
.write_all(&serde_json::to_vec_pretty(&inv)?)
.await?
}
Some(format) => {
return Err(ClientError::Other(format!("Unknown format: {}", format)))
}
None => tokio::io::stdout().write_all(&toml::to_vec(&inv)?).await?,
}
}
SubCommand::GetInvoice(gi_opts) => {
let inv = match gi_opts.yanked {
Expand Down
7 changes: 7 additions & 0 deletions bin/client/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ pub struct Info {
about = "Whether or not to fetch a yanked bindle. If you attempt to fetch a yanked bindle without this set, it will error"
)]
pub yanked: bool,
#[clap(
short = 'f',
long = "output-format",
about = "choose an output format",
possible_values = &["json", "toml"],
)]
pub output: Option<String>,
}

#[derive(Clap)]
Expand Down

0 comments on commit 440a62b

Please sign in to comment.