mirror of
https://github.com/nushell/nushell
synced 2024-12-27 05:23:11 +00:00
Add long options for filters (#10641)
This commit is contained in:
parent
bcf3537395
commit
ff6c0fcb81
22 changed files with 47 additions and 47 deletions
4
.github/workflows/release-pkg.nu
vendored
4
.github/workflows/release-pkg.nu
vendored
|
@ -188,7 +188,7 @@ if $os in [$USE_UBUNTU, 'macos-latest'] {
|
|||
cargo install cargo-wix --version 0.3.4
|
||||
cargo wix --no-build --nocapture --package nu --output $wixRelease
|
||||
# Workaround for https://github.com/softprops/action-gh-release/issues/280
|
||||
let archive = ($wixRelease | str replace -a '\' '/')
|
||||
let archive = ($wixRelease | str replace --all '\' '/')
|
||||
print $'archive: ---> ($archive)';
|
||||
echo $"archive=($archive)" | save --append $env.GITHUB_OUTPUT
|
||||
|
||||
|
@ -200,7 +200,7 @@ if $os in [$USE_UBUNTU, 'macos-latest'] {
|
|||
let pkg = (ls -f $archive | get name)
|
||||
if not ($pkg | is-empty) {
|
||||
# Workaround for https://github.com/softprops/action-gh-release/issues/280
|
||||
let archive = ($pkg | get 0 | str replace -a '\' '/')
|
||||
let archive = ($pkg | get 0 | str replace --all '\' '/')
|
||||
print $'archive: ---> ($archive)'
|
||||
echo $"archive=($archive)" | save --append $env.GITHUB_OUTPUT
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ impl Command for Default {
|
|||
Example {
|
||||
description:
|
||||
"Get the env value of `MY_ENV` with a default value 'abc' if not present",
|
||||
example: "$env | get -i MY_ENV | default 'abc'",
|
||||
example: "$env | get --ignore-errors MY_ENV | default 'abc'",
|
||||
result: None, // Some(Value::test_string("abc")),
|
||||
},
|
||||
Example {
|
||||
|
|
|
@ -124,7 +124,7 @@ impl Command for Find {
|
|||
},
|
||||
Example {
|
||||
description: "Find value in records using regex",
|
||||
example: r#"[[version name]; ['0.1.0' nushell] ['0.1.1' fish] ['0.2.0' zsh]] | find -r "nu""#,
|
||||
example: r#"[[version name]; ['0.1.0' nushell] ['0.1.1' fish] ['0.2.0' zsh]] | find --regex "nu""#,
|
||||
result: Some(Value::list(
|
||||
vec![Value::test_record(Record {
|
||||
cols: vec!["version".to_string(), "name".to_string()],
|
||||
|
@ -138,7 +138,7 @@ impl Command for Find {
|
|||
},
|
||||
Example {
|
||||
description: "Find inverted values in records using regex",
|
||||
example: r#"[[version name]; ['0.1.0' nushell] ['0.1.1' fish] ['0.2.0' zsh]] | find -r "nu" --invert"#,
|
||||
example: r#"[[version name]; ['0.1.0' nushell] ['0.1.1' fish] ['0.2.0' zsh]] | find --regex "nu" --invert"#,
|
||||
result: Some(Value::list(
|
||||
vec![
|
||||
Value::test_record(Record {
|
||||
|
@ -161,7 +161,7 @@ impl Command for Find {
|
|||
},
|
||||
Example {
|
||||
description: "Find value in list using regex",
|
||||
example: r#"[["Larry", "Moe"], ["Victor", "Marina"]] | find -r "rr""#,
|
||||
example: r#"[["Larry", "Moe"], ["Victor", "Marina"]] | find --regex "rr""#,
|
||||
result: Some(Value::list(
|
||||
vec![Value::list(
|
||||
vec![Value::test_string("Larry"), Value::test_string("Moe")],
|
||||
|
@ -172,7 +172,7 @@ impl Command for Find {
|
|||
},
|
||||
Example {
|
||||
description: "Find inverted values in records using regex",
|
||||
example: r#"[["Larry", "Moe"], ["Victor", "Marina"]] | find -r "rr" --invert"#,
|
||||
example: r#"[["Larry", "Moe"], ["Victor", "Marina"]] | find --regex "rr" --invert"#,
|
||||
result: Some(Value::list(
|
||||
vec![Value::list(
|
||||
vec![Value::test_string("Victor"), Value::test_string("Marina")],
|
||||
|
@ -189,7 +189,7 @@ impl Command for Find {
|
|||
Example {
|
||||
description: "Find and highlight text in specific columns",
|
||||
example:
|
||||
"[[col1 col2 col3]; [moe larry curly] [larry curly moe]] | find moe -c [col1]",
|
||||
"[[col1 col2 col3]; [moe larry curly] [larry curly moe]] | find moe --columns [col1]",
|
||||
result: Some(Value::list(
|
||||
vec![Value::test_record(Record {
|
||||
cols: vec!["col1".to_string(), "col2".to_string(), "col3".to_string()],
|
||||
|
|
|
@ -139,7 +139,7 @@ If multiple cell paths are given, this will produce a list of values."#
|
|||
},
|
||||
Example {
|
||||
description: "Getting Path in a case sensitive way, won't work for 'PATH'",
|
||||
example: "$env | get -s Path",
|
||||
example: "$env | get --sensitive Path",
|
||||
result: None,
|
||||
},
|
||||
]
|
||||
|
|
|
@ -58,28 +58,28 @@ impl Command for Reduce {
|
|||
},
|
||||
Example {
|
||||
example:
|
||||
"[ 8 7 6 ] | enumerate | reduce -f 0 {|it, acc| $acc + $it.item + $it.index }",
|
||||
"[ 8 7 6 ] | enumerate | reduce --fold 0 {|it, acc| $acc + $it.item + $it.index }",
|
||||
description: "Sum values of a list, plus their indexes",
|
||||
result: Some(Value::test_int(24)),
|
||||
},
|
||||
Example {
|
||||
example: "[ 1 2 3 4 ] | reduce -f 10 {|it, acc| $acc + $it }",
|
||||
example: "[ 1 2 3 4 ] | reduce --fold 10 {|it, acc| $acc + $it }",
|
||||
description: "Sum values with a starting value (fold)",
|
||||
result: Some(Value::test_int(20)),
|
||||
},
|
||||
Example {
|
||||
example: r#"[ i o t ] | reduce -f "Arthur, King of the Britons" {|it, acc| $acc | str replace -a $it "X" }"#,
|
||||
example: r#"[ i o t ] | reduce --fold "Arthur, King of the Britons" {|it, acc| $acc | str replace --all $it "X" }"#,
|
||||
description: "Replace selected characters in a string with 'X'",
|
||||
result: Some(Value::test_string("ArXhur, KXng Xf Xhe BrXXXns")),
|
||||
},
|
||||
Example {
|
||||
example: r#"['foo.gz', 'bar.gz', 'baz.gz'] | enumerate | reduce -f '' {|str all| $"($all)(if $str.index != 0 {'; '})($str.index + 1)-($str.item)" }"#,
|
||||
example: r#"['foo.gz', 'bar.gz', 'baz.gz'] | enumerate | reduce --fold '' {|str all| $"($all)(if $str.index != 0 {'; '})($str.index + 1)-($str.item)" }"#,
|
||||
description:
|
||||
"Add ascending numbers to each of the filenames, and join with semicolons.",
|
||||
result: Some(Value::test_string("1-foo.gz; 2-bar.gz; 3-baz.gz")),
|
||||
},
|
||||
Example {
|
||||
example: r#"let s = "Str"; 0..2 | reduce -f '' {|it, acc| $acc + $s}"#,
|
||||
example: r#"let s = "Str"; 0..2 | reduce --fold '' {|it, acc| $acc + $s}"#,
|
||||
description:
|
||||
"Concatenate a string with itself, using a range to determine the number of times.",
|
||||
result: Some(Value::test_string("StrStrStr")),
|
||||
|
|
|
@ -78,7 +78,7 @@ impl Command for Rename {
|
|||
},
|
||||
Example {
|
||||
description: "Rename a specific column",
|
||||
example: "[[a, b, c]; [1, 2, 3]] | rename -c { a: ham }",
|
||||
example: "[[a, b, c]; [1, 2, 3]] | rename --column { a: ham }",
|
||||
result: Some(Value::list(
|
||||
vec![Value::test_record(Record {
|
||||
cols: vec!["ham".to_string(), "b".to_string(), "c".to_string()],
|
||||
|
@ -97,7 +97,7 @@ impl Command for Rename {
|
|||
},
|
||||
Example {
|
||||
description: "Rename fields based on a given closure",
|
||||
example: "{abc: 1, bbc: 2} | rename -b {str replace -a 'b' 'z'}",
|
||||
example: "{abc: 1, bbc: 2} | rename --block {str replace --all 'b' 'z'}",
|
||||
result: Some(Value::test_record(Record {
|
||||
cols: vec!["azc".to_string(), "zzc".to_string()],
|
||||
vals: vec![Value::test_int(1), Value::test_int(2)],
|
||||
|
|
|
@ -55,7 +55,7 @@ impl Command for Sort {
|
|||
)),
|
||||
},
|
||||
Example {
|
||||
example: "[2 0 1] | sort -r",
|
||||
example: "[2 0 1] | sort --reverse",
|
||||
description: "sort the list by decreasing value",
|
||||
result: Some(Value::list(
|
||||
vec![Value::test_int(2), Value::test_int(1), Value::test_int(0)],
|
||||
|
@ -75,7 +75,7 @@ impl Command for Sort {
|
|||
)),
|
||||
},
|
||||
Example {
|
||||
example: "[betty amy sarah] | sort -r",
|
||||
example: "[betty amy sarah] | sort --reverse",
|
||||
description: "sort a list of strings in reverse",
|
||||
result: Some(Value::list(
|
||||
vec![
|
||||
|
|
|
@ -52,12 +52,12 @@ impl Command for SortBy {
|
|||
},
|
||||
Example {
|
||||
description: "Sort files by name (case-insensitive)",
|
||||
example: "ls | sort-by name -i",
|
||||
example: "ls | sort-by name --ignore-case",
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description: "Sort a table by a column (reversed order)",
|
||||
example: "[[fruit count]; [apple 9] [pear 3] [orange 7]] | sort-by fruit -r",
|
||||
example: "[[fruit count]; [apple 9] [pear 3] [orange 7]] | sort-by fruit --reverse",
|
||||
result: Some(Value::list(
|
||||
vec![
|
||||
Value::test_record(Record {
|
||||
|
|
|
@ -122,7 +122,7 @@ impl Command for Transpose {
|
|||
Example {
|
||||
description:
|
||||
"Transposes the table without column names and specify a new column name",
|
||||
example: "[[c1 c2]; [1 2]] | transpose -i val",
|
||||
example: "[[c1 c2]; [1 2]] | transpose --ignore-titles val",
|
||||
result: Some(Value::list(
|
||||
vec![
|
||||
Value::test_record(Record {
|
||||
|
@ -139,7 +139,7 @@ impl Command for Transpose {
|
|||
},
|
||||
Example {
|
||||
description: "Transfer back to record with -d flag",
|
||||
example: "{c1: 1, c2: 2} | transpose | transpose -i -r -d",
|
||||
example: "{c1: 1, c2: 2} | transpose | transpose --ignore-titles -r -d",
|
||||
result: Some(Value::test_record(Record {
|
||||
cols: vec!["c1".to_string(), "c2".to_string()],
|
||||
vals: vec![Value::test_int(1), Value::test_int(2)],
|
||||
|
|
|
@ -103,7 +103,7 @@ impl Command for Uniq {
|
|||
},
|
||||
Example {
|
||||
description: "Return the input values that occur once only",
|
||||
example: "[1 2 2] | uniq -u",
|
||||
example: "[1 2 2] | uniq --unique",
|
||||
result: Some(Value::list(
|
||||
vec![Value::test_int(1)],
|
||||
Span::test_data(),
|
||||
|
@ -111,7 +111,7 @@ impl Command for Uniq {
|
|||
},
|
||||
Example {
|
||||
description: "Ignore differences in case when comparing input values",
|
||||
example: "['hello' 'goodbye' 'Hello'] | uniq -i",
|
||||
example: "['hello' 'goodbye' 'Hello'] | uniq --ignore-case",
|
||||
result: Some(Value::list(
|
||||
vec![Value::test_string("hello"), Value::test_string("goodbye")],
|
||||
Span::test_data(),
|
||||
|
@ -119,7 +119,7 @@ impl Command for Uniq {
|
|||
},
|
||||
Example {
|
||||
description: "Return a table containing the distinct input values together with their counts",
|
||||
example: "[1 2 2] | uniq -c",
|
||||
example: "[1 2 2] | uniq --count",
|
||||
result: Some(Value::list(
|
||||
vec![
|
||||
Value::test_record(Record {
|
||||
|
|
|
@ -149,7 +149,7 @@ not supported."#
|
|||
},
|
||||
Example {
|
||||
description: "Find files whose filenames don't begin with the correct sequential number",
|
||||
example: "ls | where type == file | sort-by name -n | enumerate | where {|e| $e.item.name !~ $'^($e.index + 1)' } | each {|| get item }",
|
||||
example: "ls | where type == file | sort-by name --natural | enumerate | where {|e| $e.item.name !~ $'^($e.index + 1)' } | each {|| get item }",
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
|
|
|
@ -128,7 +128,7 @@ impl Command for SubCommand {
|
|||
},
|
||||
Example {
|
||||
description: "Split a list of chars into lists based on multiple characters",
|
||||
example: r"[a, b, c, d, a, e, f, g] | split list -r '(b|e)'",
|
||||
example: r"[a, b, c, d, a, e, f, g] | split list --regex '(b|e)'",
|
||||
result: Some(Value::list(
|
||||
vec![
|
||||
Value::list(vec![Value::test_string("a")], Span::test_data()),
|
||||
|
|
|
@ -94,7 +94,7 @@ impl Command for SubCommand {
|
|||
Example {
|
||||
description:
|
||||
"A real-world example of splitting words",
|
||||
example: "http get https://www.gutenberg.org/files/11/11-0.txt | str downcase | split words -l 2 | uniq -c | sort-by count --reverse | first 10",
|
||||
example: "http get https://www.gutenberg.org/files/11/11-0.txt | str downcase | split words -l 2 | uniq --count | sort-by count --reverse | first 10",
|
||||
result: None,
|
||||
},
|
||||
]
|
||||
|
|
|
@ -115,7 +115,7 @@ impl Command for SubCommand {
|
|||
},
|
||||
Example {
|
||||
description: "Find and replace all occurrences of a substring",
|
||||
example: r#"'abc abc abc' | str replace -a 'b' 'z'"#,
|
||||
example: r#"'abc abc abc' | str replace --all 'b' 'z'"#,
|
||||
result: Some(Value::test_string("azc azc azc")),
|
||||
},
|
||||
Example {
|
||||
|
@ -125,13 +125,13 @@ impl Command for SubCommand {
|
|||
},
|
||||
Example {
|
||||
description: "Find and replace all occurrences of find string using regular expression",
|
||||
example: "'abc abc abc' | str replace -ar 'b' 'z'",
|
||||
example: "'abc abc abc' | str replace --all --regex 'b' 'z'",
|
||||
result: Some(Value::test_string("azc azc azc")),
|
||||
},
|
||||
Example {
|
||||
description: "Find and replace all occurrences of find string in table using regular expression",
|
||||
example:
|
||||
"[[ColA ColB ColC]; [abc abc ads]] | str replace -ar 'b' 'z' ColA ColC",
|
||||
"[[ColA ColB ColC]; [abc abc ads]] | str replace --all --regex 'b' 'z' ColA ColC",
|
||||
result: Some(Value::list (
|
||||
vec![Value::test_record(Record {
|
||||
cols: vec!["ColA".to_string(), "ColB".to_string(), "ColC".to_string()],
|
||||
|
@ -147,7 +147,7 @@ impl Command for SubCommand {
|
|||
Example {
|
||||
description: "Find and replace all occurrences of find string in record using regular expression",
|
||||
example:
|
||||
"{ KeyA: abc, KeyB: abc, KeyC: ads } | str replace -ar 'b' 'z' KeyA KeyC",
|
||||
"{ KeyA: abc, KeyB: abc, KeyC: ads } | str replace --all --regex 'b' 'z' KeyA KeyC",
|
||||
result: Some(Value::test_record(Record {
|
||||
cols: vec!["KeyA".to_string(), "KeyB".to_string(), "KeyC".to_string()],
|
||||
vals: vec![
|
||||
|
@ -179,7 +179,7 @@ impl Command for SubCommand {
|
|||
},
|
||||
Example {
|
||||
description: "Find and replace on individual lines using multiline regular expression",
|
||||
example: r#""non-matching line\n123. one line\n124. another line\n" | str replace -am '^[0-9]+\. ' ''"#,
|
||||
example: r#""non-matching line\n123. one line\n124. another line\n" | str replace --all --multiline '^[0-9]+\. ' ''"#,
|
||||
result: Some(Value::test_string("non-matching line\none line\nanother line\n")),
|
||||
},
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ fn reduce_table_column() {
|
|||
echo "[{month:2,total:30}, {month:3,total:10}, {month:4,total:3}, {month:5,total:60}]"
|
||||
| from json
|
||||
| get total
|
||||
| reduce -f 20 { |it, acc| $it + $acc ** 1.05}
|
||||
| reduce --fold 20 { |it, acc| $it + $acc ** 1.05}
|
||||
| into string -d 1
|
||||
"#
|
||||
));
|
||||
|
@ -20,7 +20,7 @@ fn reduce_table_column_with_path() {
|
|||
let actual = nu!(pipeline(
|
||||
"
|
||||
[{month:2,total:30}, {month:3,total:10}, {month:4,total:3}, {month:5,total:60}]
|
||||
| reduce -f 20 { |it, acc| $it.total + $acc ** 1.05}
|
||||
| reduce --fold 20 { |it, acc| $it.total + $acc ** 1.05}
|
||||
| into string -d 1
|
||||
"
|
||||
));
|
||||
|
@ -33,7 +33,7 @@ fn reduce_rows_example() {
|
|||
let actual = nu!(pipeline(
|
||||
"
|
||||
[[a,b]; [1,2] [3,4]]
|
||||
| reduce -f 1.6 { |it, acc| $acc * ($it.a | into int) + ($it.b | into int) }
|
||||
| reduce --fold 1.6 { |it, acc| $acc * ($it.a | into int) + ($it.b | into int) }
|
||||
"
|
||||
));
|
||||
|
||||
|
@ -89,7 +89,7 @@ fn folding_with_tables() {
|
|||
let actual = nu!(pipeline(
|
||||
"
|
||||
echo [10 20 30 40]
|
||||
| reduce -f [] { |it, acc|
|
||||
| reduce --fold [] { |it, acc|
|
||||
with-env [value $it] {
|
||||
echo $acc | append (10 * ($env.value | into int))
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ fn folding_with_tables() {
|
|||
#[test]
|
||||
fn error_reduce_fold_type_mismatch() {
|
||||
let actual = nu!(pipeline(
|
||||
"echo a b c | reduce -f 0 { |it, acc| $acc + $it }"
|
||||
"echo a b c | reduce --fold 0 { |it, acc| $acc + $it }"
|
||||
));
|
||||
|
||||
assert!(actual.err.contains("mismatch"));
|
||||
|
|
|
@ -107,7 +107,7 @@ fn errors_if_columns_param_is_empty() {
|
|||
| lines
|
||||
| wrap name
|
||||
| default "arepa!" hit
|
||||
| rename -c {}
|
||||
| rename --column {}
|
||||
"#
|
||||
));
|
||||
|
||||
|
|
|
@ -225,7 +225,7 @@ fn table_with_ignore_case() {
|
|||
['Geremias', {plate: 'Bitoque', carbs: 100}]
|
||||
]
|
||||
)],
|
||||
] | uniq -i
|
||||
] | uniq --ignore-case
|
||||
"#
|
||||
));
|
||||
|
||||
|
|
|
@ -89,7 +89,7 @@ export def find-index [ # -> int
|
|||
export def intersperse [ # -> list<any>
|
||||
separator: any # the separator to be used
|
||||
] {
|
||||
reduce -f [] {|it, acc|
|
||||
reduce --fold [] {|it, acc|
|
||||
$acc ++ [$it, $separator]
|
||||
}
|
||||
| match $in {
|
||||
|
@ -122,7 +122,7 @@ export def scan [ # -> list<any>
|
|||
fn: closure # the closure to perform the scan
|
||||
--noinit(-n) # remove the initial value from the result
|
||||
] {
|
||||
reduce -f [$init] {|it, acc|
|
||||
reduce --fold [$init] {|it, acc|
|
||||
$acc ++ [(do $fn ($acc | last) $it)]
|
||||
}
|
||||
| if $noinit {
|
||||
|
@ -219,4 +219,4 @@ export def zip-into-record [ # -> table<any>
|
|||
into record
|
||||
| append ($other | into record)
|
||||
| headers
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ def create-test-record [] nothing -> record<before-each: string, after-each: str
|
|||
get 0
|
||||
}
|
||||
}
|
||||
| transpose -i -r -d
|
||||
| transpose --ignore-titles -r -d
|
||||
)
|
||||
|
||||
$template_record
|
||||
|
|
|
@ -231,7 +231,7 @@ fn dynamic_load_env() -> TestResult {
|
|||
#[test]
|
||||
fn reduce_spans() -> TestResult {
|
||||
fail_test(
|
||||
r#"let x = ([1, 2, 3] | reduce -f 0 { $it.item + 2 * $it.acc }); error make {msg: "oh that hurts", label: {text: "right here", start: (metadata $x).span.start, end: (metadata $x).span.end } }"#,
|
||||
r#"let x = ([1, 2, 3] | reduce --fold 0 { $it.item + 2 * $it.acc }); error make {msg: "oh that hurts", label: {text: "right here", start: (metadata $x).span.start, end: (metadata $x).span.end } }"#,
|
||||
"right here",
|
||||
)
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ fn can_get_help(#[case] exp_result: &str) -> TestResult {
|
|||
--f2:string, # f2 named no default
|
||||
--f3:int=33 # f3 named default 3
|
||||
] {{ true }};
|
||||
help t | ansi strip | find `{exp_result}` | get 0 | str replace -ar '^(.*({exp_result}).*)$' '$2'"#,
|
||||
help t | ansi strip | find `{exp_result}` | get 0 | str replace --all --regex '^(.*({exp_result}).*)$' '$2'"#,
|
||||
),
|
||||
exp_result,
|
||||
)
|
||||
|
|
|
@ -90,7 +90,7 @@ fn record_subtyping_3() -> TestResult {
|
|||
#[test]
|
||||
fn transpose_into_load_env() -> TestResult {
|
||||
run_test(
|
||||
"[[col1, col2]; [a, 10], [b, 20]] | transpose -i -r -d | load-env; $env.a",
|
||||
"[[col1, col2]; [a, 10], [b, 20]] | transpose --ignore-titles -r -d | load-env; $env.a",
|
||||
"10",
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue