From 2955e23bacd464a51e79046cfb407d861d04df62 Mon Sep 17 00:00:00 2001 From: Joel Natividad <1980690+jqnatividad@users.noreply.github.com> Date: Tue, 16 Jan 2024 19:48:45 -0500 Subject: [PATCH 1/3] derive PartialEq for Delimiter --- src/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index eb3906742..8fcf570b6 100644 --- a/src/config.rs +++ b/src/config.rs @@ -30,7 +30,7 @@ const NO_INDEX_WARNING_FILESIZE: u64 = 100_000_000; // 100MB // so we don't have to keep checking if the index has been created static AUTO_INDEXED: AtomicBool = AtomicBool::new(false); -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Copy, Debug, PartialEq)] pub struct Delimiter(pub u8); /// Delimiter represents values that can be passed from the command line that From 8fcd8a6c137c552a44f3010f3b1759ddedc3ee1c Mon Sep 17 00:00:00 2001 From: Joel Natividad <1980690+jqnatividad@users.noreply.github.com> Date: Tue, 16 Jan 2024 19:49:42 -0500 Subject: [PATCH 2/3] `fmt`: when `--out-delimiter` is set to "T", its interpreted as "\t" this allows us to pass this special character thru the command line parser --- src/cmd/fmt.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cmd/fmt.rs b/src/cmd/fmt.rs index a8544144b..25a85aa38 100644 --- a/src/cmd/fmt.rs +++ b/src/cmd/fmt.rs @@ -15,6 +15,8 @@ Usage: fmt options: -t, --out-delimiter The field delimiter for writing CSV data. + Must be a single character. + If set to "T", uses tab as the delimiter. [default: ,] --crlf Use '\r\n' line endings in the output. --ascii Use ASCII field and record separators. Use Substitute (U+00A1) as the @@ -25,7 +27,7 @@ fmt options: --escape The escape character to use. When not specified, quotes are escaped by doubling them. --no-final-newline Do not write a newline at the end of the output. - This makes it easier to paste the output into Excel. + This makes it easier to paste the output into Excel. Common options: -h, --help Display this message @@ -59,6 +61,10 @@ struct Args { pub fn run(argv: &[&str]) -> CliResult<()> { let mut args: Args = util::get_args(USAGE, argv)?; + if args.flag_out_delimiter == Some(Delimiter(b'T')) { + args.flag_out_delimiter = Some(Delimiter(b'\t')); + } + let rconfig = Config::new(&args.arg_input) .delimiter(args.flag_delimiter) .no_headers(true); From 7d3c7e02c4eb9a9d15344acec419d39274ffd809 Mon Sep 17 00:00:00 2001 From: Joel Natividad <1980690+jqnatividad@users.noreply.github.com> Date: Tue, 16 Jan 2024 19:50:16 -0500 Subject: [PATCH 3/3] `tests`: add test for `--out-delimiter` special value T --- tests/test_fmt.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_fmt.rs b/tests/test_fmt.rs index 397c71a3e..6f5ede37e 100644 --- a/tests/test_fmt.rs +++ b/tests/test_fmt.rs @@ -61,6 +61,16 @@ mnopqr,stuvwx\r assert_eq!(got, expected.to_string()); } +#[test] +fn fmt_tab_delimiter() { + let (wrk, mut cmd) = setup("fmt_tab_delimiter"); + cmd.args(["--out-delimiter", "T"]); + + let got: String = wrk.stdout(&mut cmd); + let expected = "h1\th2\nabcdef\tghijkl\nmnopqr\tstuvwx\n\"ab\"\"cd\"\"ef\"\tgh,ij,kl"; + assert_eq!(got, expected.to_string()); +} + #[test] fn fmt_nofinalnewline() { let (wrk, mut cmd) = setup("fmt_nofinalnewline");