Add example for command n,g,p and grid, update date now examples (#4622)

This commit is contained in:
Justin Ma
2022-02-24 20:17:05 +08:00
committed by GitHub
parent 784382edde
commit c3979ef1cf
11 changed files with 191 additions and 14 deletions

View File

@ -35,10 +35,22 @@ impl Command for SubCommand {
}
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Get the current date and display it in a given format string.",
example: r#"date now | date format "%Y-%m-%d %H:%M:%S""#,
result: None,
}]
vec![
Example {
description: "Get the current date and display it in a given format string.",
example: r#"date now | date format "%Y-%m-%d %H:%M:%S""#,
result: None,
},
Example {
description: "Get the time duration from 2019-04-30 to now",
example: r#"(date now) - 2019-05-01"#,
result: None,
},
Example {
description: "Get the time duration since a more accurate time",
example: r#"(date now) - 2019-05-01T04:12:05.20+08:00"#,
result: None,
},
]
}
}

View File

@ -1,7 +1,9 @@
use nu_engine::{current_dir, CallExt};
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Category, PipelineData, ShellError, Signature, Spanned, SyntaxShape, Value};
use nu_protocol::{
Category, Example, PipelineData, ShellError, Signature, Spanned, SyntaxShape, Value,
};
/// Source a file for environment variables.
#[derive(Clone)]
@ -75,4 +77,19 @@ impl Command for GotoShell {
Ok(PipelineData::new(call.head))
}
fn examples(&self) -> Vec<Example> {
vec![
Example {
description: "Make two directories and enter new shells for them, use `g` to jump to the specific shell",
example: r#"mkdir foo bar; enter foo; enter ../bar; g 1"#,
result: None,
},
Example {
description: "Use `shells` to show all the opened shells and run `g 2` to jump to the third one",
example: r#"shells; g 2"#,
result: None,
},
]
}
}

View File

@ -1,7 +1,7 @@
use nu_engine::current_dir;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Category, PipelineData, ShellError, Signature, Value};
use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Value};
/// Source a file for environment variables.
#[derive(Clone)]
@ -76,4 +76,19 @@ impl Command for NextShell {
Ok(PipelineData::new(call.head))
}
fn examples(&self) -> Vec<Example> {
vec![
Example {
description: "Make two directories and enter new shells for them, use `n` to jump to the next shell",
example: r#"mkdir foo bar; enter foo; enter ../bar; n"#,
result: None,
},
Example {
description: "Run `n` several times and note the changes of current directory",
example: r#"n"#,
result: None,
},
]
}
}

View File

@ -1,7 +1,7 @@
use nu_engine::current_dir;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Category, PipelineData, ShellError, Signature, Value};
use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Value};
/// Source a file for environment variables.
#[derive(Clone)]
@ -76,4 +76,19 @@ impl Command for PrevShell {
Ok(PipelineData::new(call.head))
}
fn examples(&self) -> Vec<Example> {
vec![
Example {
description: "Make two directories and enter new shells for them, use `p` to jump to the previous shell",
example: r#"mkdir foo bar; enter foo; enter ../bar; p"#,
result: None,
},
Example {
description: "Run `p` several times and note the changes of current directory",
example: r#"p"#,
result: None,
},
]
}
}

View File

@ -8,8 +8,8 @@ use nu_engine::CallExt;
use nu_protocol::{
ast::{Call, PathMember},
engine::{Command, EngineState, Stack},
Category, Config, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape,
Value,
Category, Config, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span,
SyntaxShape, Value,
};
use nu_term_grid::grid::{Alignment, Cell, Direction, Filling, Grid, GridOptions};
use terminal_size::{Height, Width};
@ -131,6 +131,51 @@ prints out the list properly."#
}
}
}
fn examples(&self) -> Vec<Example> {
vec![
Example {
description: "Render a simple list to a grid",
example: "[1 2 3 a b c] | grid",
result: Some(Value::String {
val: "1 │ 2 │ 3 │ a │ b │ c".to_string(),
span: Span::test_data(),
}),
},
Example {
description: "The above example is the same as:",
example: "[1 2 3 a b c] | wrap name | grid",
result: Some(Value::String {
val: "1 │ 2 │ 3 │ a │ b │ c".to_string(),
span: Span::test_data(),
}),
},
Example {
description: "Render a record to a grid",
example: "{name: 'foo', b: 1, c: 2} | grid",
result: Some(Value::String {
val: "foo".to_string(),
span: Span::test_data(),
}),
},
Example {
description: "Render a list of records to a grid",
example: "[{name: 'A', v: 1} {name: 'B', v: 2} {name: 'C', v: 3}] | grid",
result: Some(Value::String {
val: "A │ B │ C".to_string(),
span: Span::test_data(),
}),
},
Example {
description: "Render a table with 'name' column in it to a grid",
example: "[[name patch]; [0.1.0 $false] [0.1.1 $true] [0.2.0 $false]] | grid",
result: Some(Value::String {
val: "0.1.0 │ 0.1.1 │ 0.2.0".to_string(),
span: Span::test_data(),
}),
},
]
}
}
/// Removes ANSI escape codes and some ASCII control characters