mirror of
https://github.com/nushell/nushell.git
synced 2025-01-11 08:48:23 +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)),
|
result: Some(Value::boolean(true, span)),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "convert decimal to boolean",
|
description: "convert integer to boolean",
|
||||||
example: "1 | into bool",
|
example: "1 | into bool",
|
||||||
result: Some(Value::boolean(true, span)),
|
result: Some(Value::boolean(true, span)),
|
||||||
},
|
},
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use nu_protocol::ast::Call;
|
use nu_protocol::ast::Call;
|
||||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
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)]
|
#[derive(Clone)]
|
||||||
pub struct Debug;
|
pub struct Debug;
|
||||||
@ -52,11 +52,26 @@ impl Command for Debug {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
vec![Example {
|
vec![
|
||||||
description: "Describe the type of a string",
|
Example {
|
||||||
example: "'hello' | debug",
|
description: "Print the value of a string",
|
||||||
result: Some(Value::test_string("hello")),
|
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"#,
|
example: r#"(date now) - 2019-05-01T04:12:05.20+08:00"#,
|
||||||
result: None,
|
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(),
|
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 {
|
||||||
example: r#"[1 2 3] | each --keep-empty { |it| if $it == 2 { echo "found 2!"} }"#,
|
example: r#"[1 2 3] | each --keep-empty { |it| if $it == 2 { echo "found 2!"} }"#,
|
||||||
description: "Iterate over each element, keeping all results",
|
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::engine::{CaptureBlock, Command, EngineState, Stack};
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
Category, Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, Signature,
|
Category, Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, Signature,
|
||||||
SyntaxShape, Value,
|
Span, SyntaxShape, Value,
|
||||||
};
|
};
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
|
|
||||||
@ -31,11 +31,24 @@ impl Command for ParEach {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
vec![Example {
|
vec![
|
||||||
example: "[1 2 3] | par-each { |it| 2 * $it }",
|
Example {
|
||||||
description: "Multiplies elements in list",
|
example: "[1 2 3] | par-each { |it| 2 * $it }",
|
||||||
result: None,
|
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(
|
fn run(
|
||||||
|
@ -26,3 +26,8 @@ Get the time duration since a more accurate time
|
|||||||
```shell
|
```shell
|
||||||
> (date now) - 2019-05-01T04:12:05.20+08:00
|
> (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
|
## Examples
|
||||||
|
|
||||||
Describe the type of a string
|
Print the value of a string
|
||||||
```shell
|
```shell
|
||||||
> 'hello' | debug
|
> '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!"} }
|
> [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
|
Iterate over each element, keeping all results
|
||||||
```shell
|
```shell
|
||||||
> [1 2 3] | each --keep-empty { |it| if $it == 2 { echo "found 2!"} }
|
> [1 2 3] | each --keep-empty { |it| if $it == 2 { echo "found 2!"} }
|
||||||
|
@ -26,7 +26,7 @@ Convert bool to boolean
|
|||||||
> $true | into bool
|
> $true | into bool
|
||||||
```
|
```
|
||||||
|
|
||||||
convert decimal to boolean
|
convert integer to boolean
|
||||||
```shell
|
```shell
|
||||||
> 1 | into bool
|
> 1 | into bool
|
||||||
```
|
```
|
||||||
|
@ -21,3 +21,8 @@ Multiplies elements in list
|
|||||||
```shell
|
```shell
|
||||||
> [1 2 3] | par-each { |it| 2 * $it }
|
> [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]
|
#[test]
|
||||||
fn help_works_with_missing_requirements() -> TestResult {
|
fn help_works_with_missing_requirements() -> TestResult {
|
||||||
run_test(r#"each --help | lines | length"#, "30")
|
run_test(r#"each --help | lines | length"#, "33")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
Reference in New Issue
Block a user