mirror of
https://github.com/nushell/nushell.git
synced 2024-12-23 15:39:06 +01:00
Update some examples and docs (#4682)
* Update some examples and docs * Update now.rs * Update date_now.md Co-authored-by: JT <547158+jntrnr@users.noreply.github.com>
This commit is contained in:
parent
2a89936bee
commit
42f1874a3a
@ -80,7 +80,7 @@ impl Command for SubCommand {
|
||||
result: Some(Value::boolean(true, span)),
|
||||
},
|
||||
Example {
|
||||
description: "convert decimal to boolean",
|
||||
description: "convert integer to boolean",
|
||||
example: "1 | into bool",
|
||||
result: Some(Value::boolean(true, span)),
|
||||
},
|
||||
|
@ -1,6 +1,6 @@
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Value};
|
||||
use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Span, Value};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Debug;
|
||||
@ -52,11 +52,26 @@ impl Command for Debug {
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![Example {
|
||||
description: "Describe the type of a string",
|
||||
example: "'hello' | debug",
|
||||
result: Some(Value::test_string("hello")),
|
||||
}]
|
||||
vec![
|
||||
Example {
|
||||
description: "Print the value of a string",
|
||||
example: "'hello' | debug",
|
||||
result: Some(Value::test_string("hello")),
|
||||
},
|
||||
Example {
|
||||
description: "Print the value of a table",
|
||||
example:
|
||||
"echo [[version patch]; [0.1.0 $false] [0.1.1 $true] [0.2.0 $false]] | debug",
|
||||
result: Some(Value::List {
|
||||
vals: vec![
|
||||
Value::test_string("{version: 0.1.0, patch: false}"),
|
||||
Value::test_string("{version: 0.1.1, patch: true}"),
|
||||
Value::test_string("{version: 0.2.0, patch: false}"),
|
||||
],
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,11 @@ impl Command for SubCommand {
|
||||
example: r#"(date now) - 2019-05-01T04:12:05.20+08:00"#,
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description: "Get current time in full RFC3339 format with timezone",
|
||||
example: r#"date now | debug"#,
|
||||
result: None,
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -79,6 +79,17 @@ impl Command for Each {
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
},
|
||||
Example {
|
||||
example: r#"[1 2 3] | each -n { |it| if $it.item == 2 { echo $"found 2 at ($it.index)!"} }"#,
|
||||
description: "Iterate over each element, print the matching value and it's index",
|
||||
result: Some(Value::List {
|
||||
vals: vec![Value::String {
|
||||
val: "found 2 at 1!".to_string(),
|
||||
span: Span::test_data(),
|
||||
}],
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
},
|
||||
Example {
|
||||
example: r#"[1 2 3] | each --keep-empty { |it| if $it == 2 { echo "found 2!"} }"#,
|
||||
description: "Iterate over each element, keeping all results",
|
||||
|
@ -3,7 +3,7 @@ use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{CaptureBlock, Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
Category, Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, Signature,
|
||||
SyntaxShape, Value,
|
||||
Span, SyntaxShape, Value,
|
||||
};
|
||||
use rayon::prelude::*;
|
||||
|
||||
@ -31,11 +31,24 @@ impl Command for ParEach {
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![Example {
|
||||
example: "[1 2 3] | par-each { |it| 2 * $it }",
|
||||
description: "Multiplies elements in list",
|
||||
result: None,
|
||||
}]
|
||||
vec![
|
||||
Example {
|
||||
example: "[1 2 3] | par-each { |it| 2 * $it }",
|
||||
description: "Multiplies elements in list",
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
example: r#"[1 2 3] | par-each -n { |it| if $it.item == 2 { echo $"found 2 at ($it.index)!"} }"#,
|
||||
description: "Iterate over each element, print the matching value and it's index",
|
||||
result: Some(Value::List {
|
||||
vals: vec![Value::String {
|
||||
val: "found 2 at 1!".to_string(),
|
||||
span: Span::test_data(),
|
||||
}],
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
fn run(
|
||||
|
@ -26,3 +26,8 @@ Get the time duration since a more accurate time
|
||||
```shell
|
||||
> (date now) - 2019-05-01T04:12:05.20+08:00
|
||||
```
|
||||
|
||||
Get current time in full RFC3339 format with timezone
|
||||
```shell
|
||||
> date now | debug
|
||||
```
|
||||
|
@ -16,7 +16,12 @@ Debug print the value(s) piped in.
|
||||
|
||||
## Examples
|
||||
|
||||
Describe the type of a string
|
||||
Print the value of a string
|
||||
```shell
|
||||
> 'hello' | debug
|
||||
```
|
||||
|
||||
Print the value of a table
|
||||
```shell
|
||||
> echo [[version patch]; [0.1.0 $false] [0.1.1 $true] [0.2.0 $false]] | debug
|
||||
```
|
||||
|
@ -28,6 +28,11 @@ Iterate over each element, keeping only values that succeed
|
||||
> [1 2 3] | each { |it| if $it == 2 { echo "found 2!"} }
|
||||
```
|
||||
|
||||
Iterate over each element, print the matching value and it's index
|
||||
```shell
|
||||
> [1 2 3] | each -n { |it| if $it.item == 2 { echo $"found 2 at ($it.index)!"} }
|
||||
```
|
||||
|
||||
Iterate over each element, keeping all results
|
||||
```shell
|
||||
> [1 2 3] | each --keep-empty { |it| if $it == 2 { echo "found 2!"} }
|
||||
|
@ -26,7 +26,7 @@ Convert bool to boolean
|
||||
> $true | into bool
|
||||
```
|
||||
|
||||
convert decimal to boolean
|
||||
convert integer to boolean
|
||||
```shell
|
||||
> 1 | into bool
|
||||
```
|
||||
|
@ -21,3 +21,8 @@ Multiplies elements in list
|
||||
```shell
|
||||
> [1 2 3] | par-each { |it| 2 * $it }
|
||||
```
|
||||
|
||||
Iterate over each element, print the matching value and it's index
|
||||
```shell
|
||||
> [1 2 3] | par-each -n { |it| if $it.item == 2 { echo $"found 2 at ($it.index)!"} }
|
||||
```
|
||||
|
@ -72,7 +72,7 @@ fn in_variable_6() -> TestResult {
|
||||
|
||||
#[test]
|
||||
fn help_works_with_missing_requirements() -> TestResult {
|
||||
run_test(r#"each --help | lines | length"#, "30")
|
||||
run_test(r#"each --help | lines | length"#, "33")
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user