Skip to content

Commit

Permalink
select: use _ as a special value to indicate last column, replaci…
Browse files Browse the repository at this point in the history
…ng 9999 sentinel value

partly fixes #1871
  • Loading branch information
jqnatividad committed Jun 12, 2024
1 parent 5d1d26e commit 85f670d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/cmd/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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('[') {
Expand Down Expand Up @@ -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 <= {}.",
Expand Down

0 comments on commit 85f670d

Please sign in to comment.