forked from extern/nushell
Add long options for filters (#10641)
This commit is contained in:
@ -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")),
|
||||
},
|
||||
|
||||
|
Reference in New Issue
Block a user