Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fat: --out-delimiter now treats "T" as special value for tab character #1546

Merged
merged 3 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/cmd/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Usage:

fmt options:
-t, --out-delimiter <arg> 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
Expand All @@ -25,7 +27,7 @@ fmt options:
--escape <arg> 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
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions tests/test_fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Loading