Skip to content

Commit 602b389

Browse files
committed
feat(output): add json output
1 parent 192ca92 commit 602b389

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/cli.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,17 @@ pub struct Opts {
657657
)]
658658
pub yaml: bool,
659659

660+
/// Print results as a JSON array so you can use it with tools like jq and nushell.
661+
#[arg(
662+
long,
663+
value_name = "json",
664+
conflicts_with("format"),
665+
conflicts_with("list_details"),
666+
conflicts_with("yaml"),
667+
help = "Print results as a JSON array so you can use it with tools like jq and nushell."
668+
)]
669+
pub json: bool,
670+
660671
/// By default, relative paths are prefixed with './' when -x/--exec,
661672
/// -X/--exec-batch, or -0/--print0 are given, to reduce the risk of a
662673
/// path starting with '-' being treated as a command line option. Use

src/config.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@ pub struct Config {
131131
/// Whether or not to use hyperlinks on paths
132132
pub hyperlink: bool,
133133

134-
/// Whether or not to print the result as a JSON object
134+
/// Whether or not to print the result as a JSON array
135+
pub json: bool,
136+
137+
/// Whether or not to print the result as YAML objects
135138
pub yaml: bool,
136139
}
137140

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ fn construct_config(mut opts: Opts, pattern_regexps: &[String]) -> Result<Config
326326
actual_path_separator,
327327
max_results: opts.max_results(),
328328
strip_cwd_prefix: opts.strip_cwd_prefix(|| !(opts.null_separator || has_command)),
329+
json: opts.json,
329330
yaml: opts.yaml,
330331
})
331332
}

0 commit comments

Comments
 (0)