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
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 ")),
},
]