Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add --raw option to list command #241

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/bin/rbw/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ pub fn sync() -> anyhow::Result<()> {
Ok(())
}

pub fn list(fields: &[String]) -> anyhow::Result<()> {
pub fn list(fields: &[String], raw: bool) -> anyhow::Result<()> {
let fields: Vec<ListField> = fields
.iter()
.map(std::convert::TryFrom::try_from)
Expand All @@ -1023,6 +1023,13 @@ pub fn list(fields: &[String]) -> anyhow::Result<()> {
.collect::<anyhow::Result<_>>()?;
ciphers.sort_unstable_by(|a, b| a.name.cmp(&b.name));

if raw {
serde_json::to_writer_pretty(std::io::stdout(), &ciphers)
.context("failed to write entries to stdout")?;
println!();
return Ok(());
}

for cipher in ciphers {
let values: Vec<String> = fields
.iter()
Expand Down
4 changes: 3 additions & 1 deletion src/bin/rbw/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ enum Opt {
visible_alias = "ls"
)]
List {
#[structopt(long, help = "Display output as JSON")]
raw: bool,
#[arg(
long,
help = "Fields to display. \
Expand Down Expand Up @@ -328,7 +330,7 @@ fn main() {
Opt::Unlock => commands::unlock(),
Opt::Unlocked => commands::unlocked(),
Opt::Sync => commands::sync(),
Opt::List { fields } => commands::list(fields),
Opt::List { fields, raw } => commands::list(fields, *raw),
Opt::Get {
needle,
user,
Expand Down