Skip to content

Commit 6c53f85

Browse files
committed
fix: correct output for json in detect multi for cli
resolves #72
1 parent 288213c commit 6c53f85

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

crates/cli/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "rxing-cli"
3-
version = "0.2.2"
4-
edition = "2021"
3+
version = "0.2.3"
4+
edition = "2024"
55
description = "A command line interface for rxing supporting encoding and decoding of multiple barcode formats"
66
license="Apache-2.0"
77
repository="https://github.com/rxing-core/rxing/tree/main/crates/cli"

crates/cli/src/main.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::{
66

77
use clap::{ArgGroup, Parser, Subcommand};
88
use rxing::{BarcodeFormat, MultiFormatWriter, Writer};
9+
use serde_json::de;
910

1011
#[derive(Parser)]
1112
#[command(author, version, about, long_about = None)]
@@ -432,11 +433,25 @@ fn decode_command(
432433
};
433434
match results {
434435
Ok(result_array) => {
435-
println!("Found {} results", result_array.len());
436+
if !*detailed_results_json {
437+
println!("Found {} results", result_array.len());
438+
}else {
439+
println!("[");
440+
}
436441
for (i, result) in result_array.into_iter().enumerate() {
442+
let json_prefix = if *detailed_results_json && i > 0 {
443+
","
444+
} else {
445+
""
446+
};
447+
let prefix = if *detailed_results_json {
448+
json_prefix.to_string()
449+
} else {
450+
format!("\nResult {}:", i)
451+
};
437452
println!(
438-
"Result {}:\n{}",
439-
i,
453+
"{}\n{}",
454+
prefix,
440455
print_result(
441456
&result,
442457
*detailed_result,
@@ -446,6 +461,9 @@ fn decode_command(
446461
)
447462
);
448463
}
464+
if *detailed_results_json {
465+
println!("]");
466+
}
449467
ExitCode::SUCCESS
450468
}
451469
Err(search_err) => {

0 commit comments

Comments
 (0)