Skip to content

Commit

Permalink
pseudo: detect when more than 1 column is selected
Browse files Browse the repository at this point in the history
  • Loading branch information
jqnatividad committed Nov 2, 2023
1 parent 8419000 commit 0b09372
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/cmd/pseudo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,20 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
let mut wtr = Config::new(&args.flag_output).writer()?;

let headers = rdr.byte_headers()?.clone();
let sel = rconfig.selection(&headers)?;
let column_index = *sel.iter().next().unwrap();
let column_index = match rconfig.selection(&headers) {
Ok(sel) => {
let sel_len = sel.len();
if sel_len > 1 {
return fail_incorrectusage_clierror!(
"{sel_len} columns selected. Only one column can be selected for \
pseudonymisation."
);
}
// safety: we checked that sel.len() == 1
*sel.iter().next().unwrap()
},
Err(e) => return fail_clierror!("{e}"),
};

if !rconfig.no_headers {
wtr.write_record(&headers)?;
Expand Down

0 comments on commit 0b09372

Please sign in to comment.