Skip to content

Commit

Permalink
feat: diff add --delimiter option
Browse files Browse the repository at this point in the history
as per #2447

Also inlined `write_diff_byte_record` which is in a hot loop
  • Loading branch information
jqnatividad committed Jan 21, 2025
1 parent 96e6d28 commit 7c1967f
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/cmd/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ diff options:
Common options:
-h, --help Display this message
-o, --output <file> Write output to <file> instead of stdout.
-d, --delimiter <arg> Set ALL delimiters to this character.
Overrides --delimiter-right, --delimiter-left
and --delimiter-output.
"#;

use std::io::{self, Write};
Expand Down Expand Up @@ -129,10 +132,19 @@ struct Args {
flag_key: Option<String>,
flag_sort_columns: Option<String>,
flag_drop_equal_fields: bool,
flag_delimiter: Option<Delimiter>,
}

pub fn run(argv: &[&str]) -> CliResult<()> {
let args: Args = util::get_args(USAGE, argv)?;
let mut args: Args = util::get_args(USAGE, argv)?;

if let Some(delim) = args.flag_delimiter {
[
args.flag_delimiter_left,
args.flag_delimiter_right,
args.flag_delimiter_output,
] = [Some(delim); 3];
}

let rconfig_left = Config::new(args.arg_input_left.as_ref())
.delimiter(args.flag_delimiter_left)
Expand Down Expand Up @@ -345,6 +357,7 @@ impl<W: Write> CsvDiffWriter<W> {
Ok(())
}

#[inline]
fn write_diff_byte_record(&mut self, diff_byte_record: &DiffByteRecord) -> csv::Result<()> {
let add_sign: &[u8] = &b"+"[..];
let remove_sign: &[u8] = &b"-"[..];
Expand Down

0 comments on commit 7c1967f

Please sign in to comment.