Add expansion to from-* for lists

This commit is contained in:
Jonathan Turner 2019-08-24 19:38:38 +12:00
parent cd1e16d574
commit bb794dcfec
6 changed files with 49 additions and 6 deletions

View File

@ -97,7 +97,14 @@ fn from_csv(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStrea
}
match from_csv_string_to_value(concat_string, span) {
Ok(x) => yield ReturnSuccess::value(x),
Ok(x) => match x {
Tagged { item: Value::List(list), .. } => {
for l in list {
yield ReturnSuccess::value(l);
}
}
x => yield ReturnSuccess::value(x),
},
Err(_) => if let Some(last_tag) = latest_tag {
yield Err(ShellError::labeled_error_with_secondary(
"Could not parse as CSV",

View File

@ -89,7 +89,14 @@ fn from_ini(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStrea
}
match from_ini_string_to_value(concat_string, span) {
Ok(x) => yield ReturnSuccess::value(x),
Ok(x) => match x {
Tagged { item: Value::List(list), .. } => {
for l in list {
yield ReturnSuccess::value(l);
}
}
x => yield ReturnSuccess::value(x),
},
Err(_) => if let Some(last_tag) = latest_tag {
yield Err(ShellError::labeled_error_with_secondary(
"Could not parse as INI",

View File

@ -95,7 +95,15 @@ fn from_json(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStre
}
match from_json_string_to_value(concat_string, span) {
Ok(x) => yield ReturnSuccess::value(x),
Ok(x) =>
match x {
Tagged { item: Value::List(list), .. } => {
for l in list {
yield ReturnSuccess::value(l);
}
}
x => yield ReturnSuccess::value(x),
}
Err(_) => if let Some(last_tag) = latest_tag {
yield Err(ShellError::labeled_error_with_secondary(
"Could not parse as JSON",

View File

@ -94,7 +94,14 @@ pub fn from_toml(
}
match from_toml_string_to_value(concat_string, span) {
Ok(x) => yield ReturnSuccess::value(x),
Ok(x) => match x {
Tagged { item: Value::List(list), .. } => {
for l in list {
yield ReturnSuccess::value(l);
}
}
x => yield ReturnSuccess::value(x),
},
Err(_) => if let Some(last_tag) = latest_tag {
yield Err(ShellError::labeled_error_with_secondary(
"Could not parse as TOML",

View File

@ -108,7 +108,14 @@ fn from_xml(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStrea
}
match from_xml_string_to_value(concat_string, span) {
Ok(x) => yield ReturnSuccess::value(x),
Ok(x) => match x {
Tagged { item: Value::List(list), .. } => {
for l in list {
yield ReturnSuccess::value(l);
}
}
x => yield ReturnSuccess::value(x),
},
Err(_) => if let Some(last_tag) = latest_tag {
yield Err(ShellError::labeled_error_with_secondary(
"Could not parse as XML",

View File

@ -99,7 +99,14 @@ fn from_yaml(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStre
}
match from_yaml_string_to_value(concat_string, span) {
Ok(x) => yield ReturnSuccess::value(x),
Ok(x) => match x {
Tagged { item: Value::List(list), .. } => {
for l in list {
yield ReturnSuccess::value(l);
}
}
x => yield ReturnSuccess::value(x),
},
Err(_) => if let Some(last_tag) = latest_tag {
yield Err(ShellError::labeled_error_with_secondary(
"Could not parse as YAML",