Skip to content

Commit

Permalink
cat: also read CSV data flexibly (do not validate col count) when…
Browse files Browse the repository at this point in the history
… `--flexible` option is enabled

in connection with #1293
  • Loading branch information
jqnatividad committed Nov 9, 2023
1 parent c9f3e54 commit 2d3a969
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/cmd/cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,13 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
impl Args {
#[inline]
fn configs(&self) -> CliResult<Vec<Config>> {
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<()> {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>> = vec![];
Expand Down
2 changes: 2 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ pub fn many_configs(
inps: &[String],
delim: Option<Delimiter>,
no_headers: bool,
flexible: bool,
) -> Result<Vec<Config>, String> {
let mut inps = inps.to_vec();
if inps.is_empty() {
Expand All @@ -421,6 +422,7 @@ pub fn many_configs(
Config::new(&Some(p))
.delimiter(delim)
.no_headers(no_headers)
.flexible(flexible)
})
.collect::<Vec<_>>();
errif_greater_one_stdin(&confs)?;
Expand Down

0 comments on commit 2d3a969

Please sign in to comment.