Skip to content

Commit

Permalink
Implement --nul-output
Browse files Browse the repository at this point in the history
Introduced to jq in jqlang/jq#1990

Note that JSON can contain NUL characters (e.g. `"\u0000"`), so it is
not possible to distinguish separate values in every case, even when
using this flag
  • Loading branch information
baodrate committed Jul 7, 2023
1 parent 9c836b9 commit 2a15aef
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion jaq/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ struct Cli {
#[arg(short, long)]
join_output: bool,

/// Print NUL after each value, instead of a newline
#[arg(short = '0', long)]
nul_output: bool,

/// Color output
#[arg(long, value_name = "WHEN", default_value = "auto")]
color: Color,
Expand Down Expand Up @@ -436,7 +440,9 @@ fn print(cli: &Cli, val: Val, writer: &mut impl Write) -> io::Result<()> {
}?
}
};
if !cli.join_output {
if cli.nul_output {
write!(writer, "\0")?
} else if !cli.join_output {
writeln!(writer)?
}
Ok(())
Expand Down

0 comments on commit 2a15aef

Please sign in to comment.