forked from extern/nushell
feat: add examples for length,lines,reject,benchmark and drop column (#4547)
This commit is contained in:
parent
0f4f660759
commit
3f14b75153
@ -2,8 +2,8 @@ use nu_engine::CallExt;
|
||||
use nu_protocol::ast::{Call, CellPath};
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
Category, FromValue, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, ShellError,
|
||||
Signature, Span, SyntaxShape, Value,
|
||||
Category, Example, FromValue, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData,
|
||||
ShellError, Signature, Span, SyntaxShape, Value,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -47,6 +47,21 @@ impl Command for DropColumn {
|
||||
|
||||
dropcol(engine_state, span, input, columns_to_drop)
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![Example {
|
||||
description: "Remove the last column of a table",
|
||||
example: "echo [[lib, extension]; [nu-lib, rs] [nu-core, rb]] | drop column",
|
||||
result: Some(Value::List {
|
||||
vals: vec![Value::Record {
|
||||
cols: vec!["lib".into()],
|
||||
vals: vec![Value::test_string("nu-lib"), Value::test_string("nu-core")],
|
||||
span: Span::test_data(),
|
||||
}],
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
||||
fn dropcol(
|
||||
|
@ -2,8 +2,8 @@ use nu_engine::column::get_columns;
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
Category, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, ShellError, Signature,
|
||||
Span, Value,
|
||||
Category, Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, ShellError,
|
||||
Signature, Span, Value,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -38,6 +38,21 @@ impl Command for Length {
|
||||
length_row(call, input)
|
||||
}
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![
|
||||
Example {
|
||||
description: "Count the number of entries in a list",
|
||||
example: "echo [1 2 3 4 5] | length",
|
||||
result: Some(Value::test_int(5)),
|
||||
},
|
||||
Example {
|
||||
description: "Count the number of columns in the calendar table",
|
||||
example: "cal | length -c",
|
||||
result: Some(Value::test_int(7)),
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
// this simulates calling input | columns | length
|
||||
|
@ -1,7 +1,8 @@
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
Category, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Value,
|
||||
Category, Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Span,
|
||||
Value,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -144,4 +145,15 @@ impl Command for Lines {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![Example {
|
||||
description: "Split multi-line string into lines",
|
||||
example: "echo $'two(char nl)lines' | lines",
|
||||
result: Some(Value::List {
|
||||
vals: vec![Value::test_string("two"), Value::test_string("lines")],
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,8 @@ use nu_engine::CallExt;
|
||||
use nu_protocol::ast::{Call, CellPath};
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
Category, FromValue, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, ShellError,
|
||||
Signature, Span, SyntaxShape, Value,
|
||||
Category, Example, FromValue, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData,
|
||||
ShellError, Signature, Span, SyntaxShape, Value,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -39,6 +39,28 @@ impl Command for Reject {
|
||||
let span = call.head;
|
||||
reject(engine_state, span, input, columns)
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![
|
||||
Example {
|
||||
description: "Lists the files in a directory without showing the modified column",
|
||||
example: "ls | reject modified",
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description: "Reject the specified field in a record",
|
||||
example: "echo {a: 1, b: 2} | reject a",
|
||||
result: Some(Value::Record {
|
||||
cols: vec!["b".into()],
|
||||
vals: vec![Value::Int {
|
||||
val: 2,
|
||||
span: Span::test_data(),
|
||||
}],
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
fn reject(
|
||||
|
@ -3,7 +3,9 @@ use std::time::Instant;
|
||||
use nu_engine::{eval_block, CallExt};
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{CaptureBlock, Command, EngineState, Stack};
|
||||
use nu_protocol::{Category, IntoPipelineData, PipelineData, Signature, SyntaxShape, Value};
|
||||
use nu_protocol::{
|
||||
Category, Example, IntoPipelineData, PipelineData, Signature, SyntaxShape, Value,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Benchmark;
|
||||
@ -56,4 +58,12 @@ impl Command for Benchmark {
|
||||
|
||||
Ok(output.into_pipeline_data())
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![Example {
|
||||
description: "Benchmarks a command within a block",
|
||||
example: "benchmark { sleep 500ms }",
|
||||
result: None,
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user