From 2d3a96927e7c111f98610390e1b96afd7625f745 Mon Sep 17 00:00:00 2001 From: Joel Natividad <1980690+jqnatividad@users.noreply.github.com> Date: Thu, 9 Nov 2023 15:41:31 -0500 Subject: [PATCH] `cat`: also read CSV data `flexibly` (do not validate col count) when `--flexible` option is enabled in connection with #1293 --- src/cmd/cat.rs | 9 +++++++-- src/cmd/headers.rs | 2 +- src/util.rs | 2 ++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/cmd/cat.rs b/src/cmd/cat.rs index 34b3a374c..b730d8eb4 100644 --- a/src/cmd/cat.rs +++ b/src/cmd/cat.rs @@ -97,8 +97,13 @@ pub fn run(argv: &[&str]) -> CliResult<()> { impl Args { #[inline] fn configs(&self) -> CliResult> { - util::many_configs(&self.arg_input, self.flag_delimiter, self.flag_no_headers) - .map_err(From::from) + util::many_configs( + &self.arg_input, + self.flag_delimiter, + self.flag_no_headers, + self.flag_flexible, + ) + .map_err(From::from) } fn cat_rows(&self) -> CliResult<()> { diff --git a/src/cmd/headers.rs b/src/cmd/headers.rs index 0fa784468..65e4ea9c0 100644 --- a/src/cmd/headers.rs +++ b/src/cmd/headers.rs @@ -45,7 +45,7 @@ struct Args { pub fn run(argv: &[&str]) -> CliResult<()> { let args: Args = util::get_args(USAGE, argv)?; - let configs = util::many_configs(&args.arg_input, args.flag_delimiter, true)?; + let configs = util::many_configs(&args.arg_input, args.flag_delimiter, true, false)?; let num_inputs = configs.len(); let mut headers: Vec> = vec![]; diff --git a/src/util.rs b/src/util.rs index c1c353f83..52ac81b17 100644 --- a/src/util.rs +++ b/src/util.rs @@ -410,6 +410,7 @@ pub fn many_configs( inps: &[String], delim: Option, no_headers: bool, + flexible: bool, ) -> Result, String> { let mut inps = inps.to_vec(); if inps.is_empty() { @@ -421,6 +422,7 @@ pub fn many_configs( Config::new(&Some(p)) .delimiter(delim) .no_headers(no_headers) + .flexible(flexible) }) .collect::>(); errif_greater_one_stdin(&confs)?;