diff --git a/README.md b/README.md index dcce597a7..f7075f00a 100644 --- a/README.md +++ b/README.md @@ -158,6 +158,7 @@ Nu adheres closely to a set of goals that make up its design philosophy. As feat | nth row-number | Return only the selected row | | str (field) | Apply string function. Optional use the field of a table | | tags | Read the tags (metadata) for values | +| from-array | Expand an array/list into rows | | to-array | Collapse rows into a single list | | to-json | Convert table into .json text | | to-toml | Convert table into .toml text | diff --git a/src/cli.rs b/src/cli.rs index d5b87efa0..e09c3e92f 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -147,6 +147,7 @@ pub async fn cli() -> Result<(), Box> { context.add_commands(vec![ command("first", Box::new(first::first)), command("pick", Box::new(pick::pick)), + command("from-array", Box::new(from_array::from_array)), command("from-ini", Box::new(from_ini::from_ini)), command("from-csv", Box::new(from_csv::from_csv)), command("from-json", Box::new(from_json::from_json)), @@ -161,6 +162,7 @@ pub async fn cli() -> Result<(), Box> { command("nth", Box::new(nth::nth)), command("n", Box::new(next::next)), command("p", Box::new(prev::prev)), + command("debug", Box::new(debug::debug)), command("lines", Box::new(lines::lines)), command("pick", Box::new(pick::pick)), command("shells", Box::new(shells::shells)), diff --git a/src/commands.rs b/src/commands.rs index b3f7b3b00..f9b0aab82 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -10,9 +10,11 @@ crate mod command; crate mod config; crate mod cp; crate mod date; +crate mod debug; crate mod enter; crate mod exit; crate mod first; +crate mod from_array; crate mod from_csv; crate mod from_ini; crate mod from_json; diff --git a/src/commands/debug.rs b/src/commands/debug.rs new file mode 100644 index 000000000..ac3ab3c1c --- /dev/null +++ b/src/commands/debug.rs @@ -0,0 +1,14 @@ +use crate::errors::ShellError; +use crate::prelude::*; + +pub fn debug(args: CommandArgs, _registry: &CommandRegistry) -> Result { + let input = args.input; + + Ok(input + .values + .map(|v| { + println!("{:?}", v); + ReturnSuccess::value(v) + }) + .to_output_stream()) +} diff --git a/src/commands/from_array.rs b/src/commands/from_array.rs new file mode 100644 index 000000000..10bef6786 --- /dev/null +++ b/src/commands/from_array.rs @@ -0,0 +1,21 @@ +use crate::object::Value; +use crate::prelude::*; + +pub fn from_array( + args: CommandArgs, + _registry: &CommandRegistry, +) -> Result { + let stream = args + .input + .values + .map(|item| match item { + Tagged { + item: Value::List(vec), + .. + } => VecDeque::from(vec), + x => VecDeque::from(vec![x]), + }) + .flatten(); + + Ok(stream.to_output_stream()) +} diff --git a/src/format/table.rs b/src/format/table.rs index 1db0de12f..c6af90fdc 100644 --- a/src/format/table.rs +++ b/src/format/table.rs @@ -40,11 +40,17 @@ impl TableView { let mut entries = vec![]; for (idx, value) in values.iter().enumerate() { - let mut row: Vec = headers - .iter() - .enumerate() - .map(|(i, d)| value.get_data(d).borrow().format_leaf(Some(&headers[i]))) - .collect(); + let mut row: Vec = match value { + Tagged { + item: Value::Object(..), + .. + } => headers + .iter() + .enumerate() + .map(|(i, d)| value.get_data(d).borrow().format_leaf(Some(&headers[i]))) + .collect(), + x => vec![x.format_leaf(None)], + }; if values.len() > 1 { row.insert(0, format!("{}", Color::Black.bold().paint(idx.to_string())));