From bb794dcfecb612449bacc251e59e50edd0b4d346 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Sat, 24 Aug 2019 19:38:38 +1200 Subject: [PATCH] Add expansion to from-* for lists --- src/commands/from_csv.rs | 9 ++++++++- src/commands/from_ini.rs | 9 ++++++++- src/commands/from_json.rs | 10 +++++++++- src/commands/from_toml.rs | 9 ++++++++- src/commands/from_xml.rs | 9 ++++++++- src/commands/from_yaml.rs | 9 ++++++++- 6 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/commands/from_csv.rs b/src/commands/from_csv.rs index dc0426360..1c1340092 100644 --- a/src/commands/from_csv.rs +++ b/src/commands/from_csv.rs @@ -97,7 +97,14 @@ fn from_csv(args: CommandArgs, registry: &CommandRegistry) -> Result 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", diff --git a/src/commands/from_ini.rs b/src/commands/from_ini.rs index 70b34d7d5..d1f7bb4f8 100644 --- a/src/commands/from_ini.rs +++ b/src/commands/from_ini.rs @@ -89,7 +89,14 @@ fn from_ini(args: CommandArgs, registry: &CommandRegistry) -> Result 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", diff --git a/src/commands/from_json.rs b/src/commands/from_json.rs index 311885f45..dba9e0209 100644 --- a/src/commands/from_json.rs +++ b/src/commands/from_json.rs @@ -95,7 +95,15 @@ fn from_json(args: CommandArgs, registry: &CommandRegistry) -> Result 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", diff --git a/src/commands/from_toml.rs b/src/commands/from_toml.rs index afa408534..be9a8cc6c 100644 --- a/src/commands/from_toml.rs +++ b/src/commands/from_toml.rs @@ -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", diff --git a/src/commands/from_xml.rs b/src/commands/from_xml.rs index 6f7790a28..adf39240d 100644 --- a/src/commands/from_xml.rs +++ b/src/commands/from_xml.rs @@ -108,7 +108,14 @@ fn from_xml(args: CommandArgs, registry: &CommandRegistry) -> Result 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", diff --git a/src/commands/from_yaml.rs b/src/commands/from_yaml.rs index be91bbc24..349a6faee 100644 --- a/src/commands/from_yaml.rs +++ b/src/commands/from_yaml.rs @@ -99,7 +99,14 @@ fn from_yaml(args: CommandArgs, registry: &CommandRegistry) -> Result 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",