From 85f670dba0718b2efacfe88f4bfd74a3b8ac04ae Mon Sep 17 00:00:00 2001 From: Joel Natividad <1980690+jqnatividad@users.noreply.github.com> Date: Wed, 12 Jun 2024 08:47:11 -0400 Subject: [PATCH 1/2] `select`: use `_` as a special value to indicate last column, replacing 9999 sentinel value partly fixes #1871 --- src/cmd/select.rs | 6 +++--- src/select.rs | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/cmd/select.rs b/src/cmd/select.rs index 424a094aa..760012b7a 100644 --- a/src/cmd/select.rs +++ b/src/cmd/select.rs @@ -21,11 +21,11 @@ selected using regular expressions. Select the third column named 'Foo': $ qsv select 'Foo[2]' - Select the first and last columns, 9999 is a special index for the last column: - $ qsv select 1,9999 + Select the first and last columns, _ is a special character for the last column: + $ qsv select 1,_ Reverse the order of columns: - $ qsv select 9999-1 + $ qsv select _-1 Sort the columns lexicographically. Note that you must provide a dummy selector: $ qsv select 1 --sort diff --git a/src/select.rs b/src/select.rs index d49c7015d..f79e25088 100644 --- a/src/select.rs +++ b/src/select.rs @@ -157,6 +157,10 @@ impl SelectorParser { self.bump(); self.parse_quoted_name()? } else { + if self.cur() == Some('_') { + self.bump(); + return Ok(OneSelector::End); + } self.parse_name() }; Ok(if self.cur() == Some('[') { @@ -318,14 +322,10 @@ impl OneSelector { } else { first_record.len() - 1 }), - OneSelector::Index(mut i) => { + OneSelector::Index(i) => { if first_record.is_empty() { return fail!("Input is empty."); } - // 9999 is a sentinel value that means "last column". - if i == 9999 { - i = first_record.len(); - } if i < 1 || i > first_record.len() { fail_format!( "Selector index {i} is out of bounds. Index must be >= 1 and <= {}.", From 18e472ea0b8cb6a87f6aeacdda9bc94840632162 Mon Sep 17 00:00:00 2001 From: Joel Natividad <1980690+jqnatividad@users.noreply.github.com> Date: Wed, 12 Jun 2024 08:47:48 -0400 Subject: [PATCH 2/2] `tests`: update `select` test for last column to use underscore char instead of 9999 sentinel value --- tests/test_select.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_select.rs b/tests/test_select.rs index 6ef4c9306..253ff01b9 100644 --- a/tests/test_select.rs +++ b/tests/test_select.rs @@ -180,7 +180,7 @@ select_test!( select_test!( select_reverse_sentinel, - r#"9999-1"#, + r#"_-1"#, "5-1", ["h1", "h4", "h[]3", "h2", "h1"], ["e", "d", "c", "b", "a"]