Remove unnecessary echo uses from examples (#7500)

`echo` tends to confuse new Nu users; they expect it to work like
`print` when it just passes a value to the next stage of the pipeline.

We haven't quite figured out what to do about `echo` in the long run,
but I think a good start is to remove `echo` from command examples where
it would be unnecessary and arguably unidiomatic.
This commit is contained in:
Reilly Wood
2022-12-16 08:51:00 -08:00
committed by GitHub
parent 9c1a3aa244
commit e72cecf457
32 changed files with 64 additions and 59 deletions

View File

@ -55,7 +55,7 @@ impl Command for DetectColumns {
vec![
Example {
description: "Splits string across multiple columns",
example: "echo 'a b c' | detect columns -n",
example: "'a b c' | detect columns -n",
result: Some(Value::List {
vals: vec![Value::Record {
cols: vec![
@ -75,7 +75,7 @@ impl Command for DetectColumns {
},
Example {
description: "Splits a multi-line string into columns with headers detected",
example: "echo $'c1 c2 c3(char nl)a b c' | detect columns",
example: "$'c1 c2 c3(char nl)a b c' | detect columns",
result: None,
},
]

View File

@ -51,12 +51,12 @@ impl Command for DecodeBase64 {
vec![
Example {
description: "Base64 decode a value and output as UTF-8 string",
example: "echo 'U29tZSBEYXRh' | decode base64",
example: "'U29tZSBEYXRh' | decode base64",
result: Some(Value::string("Some Data", Span::test_data())),
},
Example {
description: "Base64 decode a value and output as binary",
example: "echo 'U29tZSBEYXRh' | decode base64 --binary",
example: "'U29tZSBEYXRh' | decode base64 --binary",
result: Some(Value::binary(
[0x53, 0x6f, 0x6d, 0x65, 0x20, 0x44, 0x61, 0x74, 0x61],
Span::test_data(),

View File

@ -40,12 +40,12 @@ impl Command for EncodeBase64 {
vec![
Example {
description: "Base64 encode a string with default settings",
example: "echo 'Some Data' | encode base64",
example: "'Some Data' | encode base64",
result: Some(Value::string("U29tZSBEYXRh", Span::test_data())),
},
Example {
description: "Base64 encode a string with the binhex character set",
example: "echo 'Some Data' | encode base64 --character-set binhex",
example: "'Some Data' | encode base64 --character-set binhex",
result: Some(Value::string(r#"7epXB5"%A@4J"#, Span::test_data())),
},
]

View File

@ -78,7 +78,7 @@ impl Command for Format {
},
Example {
description: "Print elements from some columns of a table",
example: "echo [[col1, col2]; [v1, v2] [v3, v4]] | format '{col2}'",
example: "[[col1, col2]; [v1, v2] [v3, v4]] | format '{col2}'",
result: Some(Value::List {
vals: vec![Value::test_string("v2"), Value::test_string("v4")],
span: Span::test_data(),

View File

@ -48,69 +48,73 @@ impl Command for Parse {
vec![
Example {
description: "Parse a string into two named columns",
example: "echo \"hi there\" | parse \"{foo} {bar}\"",
example: "\"hi there\" | parse \"{foo} {bar}\"",
result: Some(result.clone()),
},
Example {
description: "Parse a string using regex pattern",
example: "echo \"hi there\" | parse -r '(?P<foo>\\w+) (?P<bar>\\w+)'",
example: "\"hi there\" | parse -r '(?P<foo>\\w+) (?P<bar>\\w+)'",
result: Some(result),
},
Example {
description: "Parse a string using fancy-regex named capture group pattern",
example: "echo \"foo bar.\" | parse -r '\\s*(?<name>\\w+)(?=\\.)'",
example: "\"foo bar.\" | parse -r '\\s*(?<name>\\w+)(?=\\.)'",
result: Some(Value::List {
vals: vec![Value::Record {
cols: vec!["name".to_string()],
vals: vec![Value::test_string("bar")],
span: Span::test_data()
span: Span::test_data(),
}],
span: Span::test_data(),
}),
},
Example {
description: "Parse a string using fancy-regex capture group pattern",
example: "echo \"foo! bar.\" | parse -r '(\\w+)(?=\\.)|(\\w+)(?=!)'",
example: "\"foo! bar.\" | parse -r '(\\w+)(?=\\.)|(\\w+)(?=!)'",
result: Some(Value::List {
vals: vec![
Value::Record {
cols: vec!["Capture1".to_string(), "Capture2".to_string()],
vals: vec![Value::test_string(""), Value::test_string("foo")],
span: Span::test_data()
span: Span::test_data(),
},
Value::Record {
cols: vec!["Capture1".to_string(), "Capture2".to_string()],
vals: vec![Value::test_string("bar"), Value::test_string("")],
span: Span::test_data(),
}],
},
],
span: Span::test_data(),
}),
},
Example {
description: "Parse a string using fancy-regex look behind pattern",
example: "echo \" @another(foo bar) \" | parse -r '\\s*(?<=[() ])(@\\w+)(\\([^)]*\\))?\\s*'",
example:
"\" @another(foo bar) \" | parse -r '\\s*(?<=[() ])(@\\w+)(\\([^)]*\\))?\\s*'",
result: Some(Value::List {
vals: vec![Value::Record {
cols: vec!["Capture1".to_string(), "Capture2".to_string()],
vals: vec![Value::test_string("@another"), Value::test_string("(foo bar)")],
span: Span::test_data()
vals: vec![
Value::test_string("@another"),
Value::test_string("(foo bar)"),
],
span: Span::test_data(),
}],
span: Span::test_data(),
}),
},
Example {
description: "Parse a string using fancy-regex look ahead atomic group pattern",
example: "echo \"abcd\" | parse -r '^a(bc(?=d)|b)cd$'",
example: "\"abcd\" | parse -r '^a(bc(?=d)|b)cd$'",
result: Some(Value::List {
vals: vec![Value::Record {
cols: vec!["Capture1".to_string()],
vals: vec![Value::test_string("b")],
span: Span::test_data()
span: Span::test_data(),
}],
span: Span::test_data(),
}),
},
]
}

View File

@ -60,7 +60,7 @@ impl Command for SubCommand {
vec![
Example {
description: "Split a string into columns by the specified separator",
example: "echo 'a--b--c' | split column '--'",
example: "'a--b--c' | split column '--'",
result: Some(Value::List {
vals: vec![Value::Record {
cols: vec![

View File

@ -54,7 +54,7 @@ impl Command for SubCommand {
vec![
Example {
description: "Split a string into rows of char",
example: "echo 'abc' | split row ''",
example: "'abc' | split row ''",
result: Some(Value::List {
vals: vec![
Value::test_string(""),
@ -68,7 +68,7 @@ impl Command for SubCommand {
},
Example {
description: "Split a string into rows by the specified separator",
example: "echo 'a--b--c' | split row '--'",
example: "'a--b--c' | split row '--'",
result: Some(Value::List {
vals: vec![
Value::test_string("a"),
@ -80,7 +80,7 @@ impl Command for SubCommand {
},
Example {
description: "Split a string by '-'",
example: "echo '-a-b-c-' | split row '-'",
example: "'-a-b-c-' | split row '-'",
result: Some(Value::List {
vals: vec![
Value::test_string(""),