feat: update: #4518, Add examples for command: hide, history, from yml, def-env, and table (#4581)

This commit is contained in:
Justin Ma
2022-02-21 21:52:50 +08:00
committed by GitHub
parent 4f367a59de
commit 917886f8ad
7 changed files with 136 additions and 46 deletions

View File

@ -25,42 +25,7 @@ impl Command for FromYaml {
}
fn examples(&self) -> Vec<Example> {
vec![
Example {
example: "'a: 1' | from yaml",
description: "Converts yaml formatted string to table",
result: Some(Value::Record {
cols: vec!["a".to_string()],
vals: vec![Value::Int {
val: 1,
span: Span::test_data(),
}],
span: Span::test_data(),
}),
},
Example {
example: "'[ a: 1, b: [1, 2] ]' | from yaml",
description: "Converts yaml formatted string to table",
result: Some(Value::List {
vals: vec![
Value::Record {
cols: vec!["a".to_string()],
vals: vec![Value::test_int(1)],
span: Span::test_data(),
},
Value::Record {
cols: vec!["b".to_string()],
vals: vec![Value::List {
vals: vec![Value::test_int(1), Value::test_int(2)],
span: Span::test_data(),
}],
span: Span::test_data(),
},
],
span: Span::test_data(),
}),
},
]
get_examples()
}
fn run(
@ -103,6 +68,10 @@ impl Command for FromYml {
let config = stack.get_config().unwrap_or_default();
from_yaml(input, head, &config)
}
fn examples(&self) -> Vec<Example> {
get_examples()
}
}
fn convert_yaml_value_to_nu_value(v: &serde_yaml::Value, span: Span) -> Result<Value, ShellError> {
@ -205,6 +174,45 @@ pub fn from_yaml_string_to_value(s: String, span: Span) -> Result<Value, ShellEr
}
}
pub fn get_examples() -> Vec<Example> {
vec![
Example {
example: "'a: 1' | from yaml",
description: "Converts yaml formatted string to table",
result: Some(Value::Record {
cols: vec!["a".to_string()],
vals: vec![Value::Int {
val: 1,
span: Span::test_data(),
}],
span: Span::test_data(),
}),
},
Example {
example: "'[ a: 1, b: [1, 2] ]' | from yaml",
description: "Converts yaml formatted string to table",
result: Some(Value::List {
vals: vec![
Value::Record {
cols: vec!["a".to_string()],
vals: vec![Value::test_int(1)],
span: Span::test_data(),
},
Value::Record {
cols: vec!["b".to_string()],
vals: vec![Value::List {
vals: vec![Value::test_int(1), Value::test_int(2)],
span: Span::test_data(),
}],
span: Span::test_data(),
},
],
span: Span::test_data(),
}),
},
]
}
fn from_yaml(input: PipelineData, head: Span, config: &Config) -> Result<PipelineData, ShellError> {
let concat_string = input.collect_string("", config)?;