mirror of
https://github.com/nushell/nushell.git
synced 2025-07-08 10:27:47 +02:00
This commit is contained in:
@ -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)?;
|
||||
|
||||
|
Reference in New Issue
Block a user