Use long options for string (#10777)

This commit is contained in:
Hofer-Julian 2023-10-19 22:08:09 +02:00 committed by GitHub
parent 11480c77be
commit d0dc6986dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 60 additions and 55 deletions

View file

@ -202,17 +202,17 @@ impl Command for Char {
},
Example {
description: "Output Unicode character",
example: r#"char -u 1f378"#,
example: r#"char --unicode 1f378"#,
result: Some(Value::test_string("\u{1f378}")),
},
Example {
description: "Create Unicode from integer codepoint values",
example: r#"char -i (0x60 + 1) (0x60 + 2)"#,
example: r#"char --integer (0x60 + 1) (0x60 + 2)"#,
result: Some(Value::test_string("ab")),
},
Example {
description: "Output multi-byte Unicode character",
example: r#"char -u 1F468 200D 1F466 200D 1F466"#,
example: r#"char --unicode 1F468 200D 1F466 200D 1F466"#,
result: Some(Value::test_string(
"\u{1F468}\u{200D}\u{1F466}\u{200D}\u{1F466}",
)),

View file

@ -62,7 +62,7 @@ impl Command for DetectColumns {
vec![
Example {
description: "Splits string across multiple columns",
example: "'a b c' | detect columns -n",
example: "'a b c' | detect columns --no-headers",
result: Some(Value::list(
vec![Value::test_record(Record {
cols: vec![
@ -81,17 +81,20 @@ impl Command for DetectColumns {
},
Example {
description: "",
example: "$'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns -c 0..1",
example:
"$'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns --combine-columns 0..1",
result: None,
},
Example {
description: "Splits a multi-line string into columns with headers detected",
example: "$'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns -c -2..-1",
example:
"$'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns --combine-columns -2..-1",
result: None,
},
Example {
description: "Splits a multi-line string into columns with headers detected",
example: "$'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns -c 2..",
example:
"$'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns --combine-columns 2..",
result: None,
},
Example {

View file

@ -65,7 +65,7 @@ documentation link at https://docs.rs/encoding_rs/latest/encoding_rs/#statics"#
},
Example {
description: "Replace characters with HTML entities if they can't be encoded",
example: r#""🎈" | encode -i shift-jis"#,
example: r#""🎈" | encode --ignore-errors shift-jis"#,
result: Some(Value::binary(
vec![0x26, 0x23, 0x31, 0x32, 0x37, 0x38, 0x38, 0x30, 0x3b],
Span::test_data(),

View file

@ -59,12 +59,12 @@ impl Command for Parse {
},
Example {
description: "Parse a string using regex pattern",
example: "\"hi there\" | parse -r '(?P<foo>\\w+) (?P<bar>\\w+)'",
example: "\"hi there\" | parse --regex '(?P<foo>\\w+) (?P<bar>\\w+)'",
result: Some(result),
},
Example {
description: "Parse a string using fancy-regex named capture group pattern",
example: "\"foo bar.\" | parse -r '\\s*(?<name>\\w+)(?=\\.)'",
example: "\"foo bar.\" | parse --regex '\\s*(?<name>\\w+)(?=\\.)'",
result: Some(Value::list(
vec![Value::test_record(Record {
cols: vec!["name".to_string()],
@ -75,7 +75,7 @@ impl Command for Parse {
},
Example {
description: "Parse a string using fancy-regex capture group pattern",
example: "\"foo! bar.\" | parse -r '(\\w+)(?=\\.)|(\\w+)(?=!)'",
example: "\"foo! bar.\" | parse --regex '(\\w+)(?=\\.)|(\\w+)(?=!)'",
result: Some(Value::list(
vec![
Value::test_record(Record {
@ -93,7 +93,7 @@ impl Command for Parse {
Example {
description: "Parse a string using fancy-regex look behind pattern",
example:
"\" @another(foo bar) \" | parse -r '\\s*(?<=[() ])(@\\w+)(\\([^)]*\\))?\\s*'",
"\" @another(foo bar) \" | parse --regex '\\s*(?<=[() ])(@\\w+)(\\([^)]*\\))?\\s*'",
result: Some(Value::list(
vec![Value::test_record(Record {
cols: vec!["capture0".to_string(), "capture1".to_string()],
@ -107,7 +107,7 @@ impl Command for Parse {
},
Example {
description: "Parse a string using fancy-regex look ahead atomic group pattern",
example: "\"abcd\" | parse -r '^a(bc(?=d)|b)cd$'",
example: "\"abcd\" | parse --regex '^a(bc(?=d)|b)cd$'",
result: Some(Value::list(
vec![Value::test_record(Record {
cols: vec!["capture0".to_string()],

View file

@ -59,7 +59,7 @@ impl Command for SubCommand {
},
Example {
description: "Split on grapheme clusters",
example: "'🇯🇵ほげ' | split chars -g",
example: "'🇯🇵ほげ' | split chars --grapheme-clusters",
result: Some(Value::list(
vec![
Value::test_string("🇯🇵"),

View file

@ -81,7 +81,7 @@ impl Command for SubCommand {
},
Example {
description: "Split a string into columns of char and remove the empty columns",
example: "'abc' | split column -c ''",
example: "'abc' | split column --collapse-empty ''",
result: Some(Value::list(
vec![Value::test_record(Record {
cols: vec![
@ -117,7 +117,7 @@ impl Command for SubCommand {
},
Example {
description: "Split a list of strings into a table, ignoring padding",
example: r"['a - b' 'c - d'] | split column -r '\s*-\s*'",
example: r"['a - b' 'c - d'] | split column --regex '\s*-\s*'",
result: Some(Value::list(
vec![
Value::test_record(Record {

View file

@ -81,7 +81,7 @@ impl Command for SubCommand {
Example {
description:
"Split the string's words, of at least 3 characters, into separate rows",
example: "'hello to the world' | split words -l 3",
example: "'hello to the world' | split words --min-word-length 3",
result: Some(Value::list(
vec![
Value::test_string("hello"),
@ -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 --count | sort-by count --reverse | first 10",
example: "http get https://www.gutenberg.org/files/11/11-0.txt | str downcase | split words --min-word-length 2 | uniq --count | sort-by count --reverse | first 10",
result: None,
},
]

View file

@ -83,7 +83,7 @@ impl Command for SubCommand {
},
Example {
description: "Check if input contains string case insensitive",
example: "'my_library.rb' | str contains -i '.RB'",
example: "'my_library.rb' | str contains --ignore-case '.RB'",
result: Some(Value::test_bool(true)),
},
Example {
@ -96,7 +96,7 @@ impl Command for SubCommand {
},
Example {
description: "Check if input contains string in a table",
example: " [[ColA ColB]; [test 100]] | str contains -i 'E' ColA",
example: " [[ColA ColB]; [test 100]] | str contains --ignore-case 'E' ColA",
result: Some(Value::list(
vec![Value::test_record(Record {
cols: vec!["ColA".to_string(), "ColB".to_string()],
@ -135,7 +135,7 @@ impl Command for SubCommand {
},
Example {
description: "Check if list does not contain string",
example: "[one two three] | str contains -n o",
example: "[one two three] | str contains --not o",
result: Some(Value::list(
vec![
Value::test_bool(false),

View file

@ -87,7 +87,7 @@ impl Command for SubCommand {
},
Example {
description: "Checks if string ends with '.RB', case-insensitive",
example: "'my_library.rb' | str ends-with -i '.RB'",
example: "'my_library.rb' | str ends-with --ignore-case '.RB'",
result: Some(Value::test_bool(true)),
},
]

View file

@ -107,22 +107,22 @@ impl Command for SubCommand {
},
Example {
description: "Count length using grapheme clusters",
example: "'🇯🇵ほげ ふが ぴよ' | str index-of -g 'ふが'",
example: "'🇯🇵ほげ ふが ぴよ' | str index-of --grapheme-clusters 'ふが'",
result: Some(Value::test_int(4)),
},
Example {
description: "Returns index of string in input within a`rhs open range`",
example: " '.rb.rb' | str index-of '.rb' -r 1..",
example: " '.rb.rb' | str index-of '.rb' --range 1..",
result: Some(Value::test_int(3)),
},
Example {
description: "Returns index of string in input within a lhs open range",
example: " '123456' | str index-of '6' -r ..4",
example: " '123456' | str index-of '6' --range ..4",
result: Some(Value::test_int(-1)),
},
Example {
description: "Returns index of string in input within a range",
example: " '123456' | str index-of '3' -r 1..4",
example: " '123456' | str index-of '3' --range 1..4",
result: Some(Value::test_int(2)),
},
Example {

View file

@ -96,7 +96,7 @@ impl Command for SubCommand {
},
Example {
description: "Count length using grapheme clusters",
example: "'🇯🇵ほげ ふが ぴよ' | str length -g",
example: "'🇯🇵ほげ ふが ぴよ' | str length --grapheme-clusters",
result: Some(Value::test_int(9)),
},
Example {

View file

@ -92,7 +92,7 @@ impl Command for SubCommand {
},
Example {
description: "Checks if input string starts with 'cargo', case-insensitive",
example: "'Cargo.toml' | str starts-with -i 'cargo'",
example: "'Cargo.toml' | str starts-with --ignore-case 'cargo'",
result: Some(Value::test_bool(true)),
},
]

View file

@ -117,7 +117,7 @@ impl Command for SubCommand {
},
Example {
description: "Count indexes and split using grapheme clusters",
example: " '🇯🇵ほげ ふが ぴよ' | str substring -g 4..6",
example: " '🇯🇵ほげ ふが ぴよ' | str substring --grapheme-clusters 4..6",
result: Some(Value::test_string("ふが")),
},
]

View file

@ -134,27 +134,27 @@ impl Command for SubCommand {
},
Example {
description: "Trim a specific character",
example: "'=== Nu shell ===' | str trim -c '=' | str trim",
example: "'=== Nu shell ===' | str trim --char '=' | str trim",
result: Some(Value::test_string("Nu shell")),
},
Example {
description: "Trim whitespace from the beginning of string",
example: "' Nu shell ' | str trim -l",
example: "' Nu shell ' | str trim --left",
result: Some(Value::test_string("Nu shell ")),
},
Example {
description: "Trim a specific character",
example: "'=== Nu shell ===' | str trim -c '='",
example: "'=== Nu shell ===' | str trim --char '='",
result: Some(Value::test_string(" Nu shell ")),
},
Example {
description: "Trim whitespace from the end of string",
example: "' Nu shell ' | str trim -r",
example: "' Nu shell ' | str trim --right",
result: Some(Value::test_string(" Nu shell")),
},
Example {
description: "Trim a specific character",
example: "'=== Nu shell ===' | str trim -r -c '='",
example: "'=== Nu shell ===' | str trim --right --char '='",
result: Some(Value::test_string("=== Nu shell ")),
},
]

View file

@ -187,17 +187,17 @@ impl Command for NuCheck {
},
Example {
description: "Parse a input file by showing error message",
example: "nu-check -d script.nu",
example: "nu-check --debug script.nu",
result: None,
},
Example {
description: "Parse an external stream as script by showing error message",
example: "open foo.nu | nu-check -d script.nu",
example: "open foo.nu | nu-check --debug script.nu",
result: None,
},
Example {
description: "Parse an internal stream as module by showing error message",
example: "open module.nu | lines | nu-check -d --as-module module.nu",
example: "open module.nu | lines | nu-check --debug --as-module module.nu",
result: None,
},
Example {
@ -212,7 +212,7 @@ impl Command for NuCheck {
},
Example {
description: "Heuristically parse by showing error message",
example: "open foo.nu | lines | nu-check -ad",
example: "open foo.nu | lines | nu-check --all --debug",
result: None,
},
]

View file

@ -49,7 +49,7 @@ fn detect_columns_with_flag_c() {
for case in cases.into_iter() {
let out = nu!(
cwd: dirs.test(),
"({} | detect columns -c {}) == {}",
"({} | detect columns --combine-columns {}) == {}",
case.0,
case.2,
case.1,
@ -57,7 +57,7 @@ fn detect_columns_with_flag_c() {
assert_eq!(
out.out, "true",
"({} | detect columns -c {}) == {}",
"({} | detect columns --combine-columns {}) == {}",
case.0, case.2, case.1
);
}

View file

@ -44,7 +44,7 @@ fn parse_script_with_wrong_type() {
let actual = nu!(
cwd: dirs.test(), pipeline(
"
nu-check -d --as-module script.nu
nu-check --debug --as-module script.nu
"
));
@ -68,7 +68,7 @@ fn parse_script_failure() {
let actual = nu!(
cwd: dirs.test(), pipeline(
"
nu-check -d script.nu
nu-check --debug script.nu
"
));
@ -126,7 +126,7 @@ fn parse_module_with_wrong_type() {
let actual = nu!(
cwd: dirs.test(), pipeline(
"
nu-check -d foo.nu
nu-check --debug foo.nu
"
));
@ -154,7 +154,7 @@ fn parse_module_failure() {
let actual = nu!(
cwd: dirs.test(), pipeline(
"
nu-check -d --as-module foo.nu
nu-check --debug --as-module foo.nu
"
));
@ -319,7 +319,7 @@ fn parse_string_as_script() {
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
echo $'two(char nl)lines' | nu-check -d --as-module
echo $'two(char nl)lines' | nu-check --debug --as-module
"#
));
@ -545,7 +545,7 @@ fn parse_module_success_with_complex_external_stream() {
let actual = nu!(
cwd: dirs.test(), pipeline(
"
open grep.nu | nu-check -d --as-module
open grep.nu | nu-check --debug --as-module
"
));
@ -594,7 +594,7 @@ fn parse_with_flag_all_success_for_complex_external_stream() {
let actual = nu!(
cwd: dirs.test(), pipeline(
"
open grep.nu | nu-check -ad
open grep.nu | nu-check --all --debug
"
));
@ -643,7 +643,7 @@ fn parse_with_flag_all_failure_for_complex_external_stream() {
let actual = nu!(
cwd: dirs.test(), pipeline(
"
open grep.nu | nu-check -ad
open grep.nu | nu-check --all --debug
"
));
@ -692,7 +692,7 @@ fn parse_with_flag_all_failure_for_complex_list_stream() {
let actual = nu!(
cwd: dirs.test(), pipeline(
"
open grep.nu | lines | nu-check -ad
open grep.nu | lines | nu-check --all --debug
"
));

View file

@ -186,8 +186,9 @@ fn select_ignores_errors_successfully3() {
#[test]
fn select_ignores_errors_successfully4() {
let actual =
nu!(r#""key val\na 1\nb 2\n" | lines | split column -c " " | select foo? | to nuon"#);
let actual = nu!(
r#""key val\na 1\nb 2\n" | lines | split column --collapse-empty " " | select foo? | to nuon"#
);
assert_eq!(actual.out, r#"[[foo]; [null], [null], [null]]"#.to_string());
assert!(actual.err.is_empty());
@ -211,7 +212,8 @@ fn select_failed2() {
#[test]
fn select_failed3() {
let actual = nu!(r#""key val\na 1\nb 2\n" | lines | split column -c " " | select "100""#);
let actual =
nu!(r#""key val\na 1\nb 2\n" | lines | split column --collapse-empty " " | select "100""#);
assert!(actual.out.is_empty());
assert!(actual.err.contains("cannot find column"));

View file

@ -39,7 +39,7 @@ fn to_column() {
open sample2.txt
| lines
| str trim
| split column -r '\s*,\s*'
| split column --regex '\s*,\s*'
| get column2
"
));

View file

@ -29,7 +29,7 @@ fn trims() {
fn error_trim_multiple_chars() {
let actual = nu!(pipeline(
r#"
echo "does it work now?!" | str trim -c "?!"
echo "does it work now?!" | str trim --char "?!"
"#
));

View file

@ -43,7 +43,7 @@ def get-annotated [
| where annotation in (valid-annotations|columns)
| reject index
| update item {
split column -c ' '
split column --collapse-empty ' '
| get column2.0
}
| rename function_name