diff --git a/Cargo.lock b/Cargo.lock index cad63d184f..48c884cde7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1979,7 +1979,7 @@ dependencies = [ "regex 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.9.19 (registry+https://github.com/rust-lang/crates.io-index)", "roxmltree 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustyline 5.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rustyline 5.0.1 (git+https://github.com/kkawakam/rustyline.git)", "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", "serde-hjson 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2790,7 +2790,7 @@ dependencies = [ [[package]] name = "rustyline" version = "5.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" +source = "git+https://github.com/kkawakam/rustyline.git#568c9d0512b065e9eef68a6e46407881d2376738" dependencies = [ "dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4036,7 +4036,7 @@ dependencies = [ "checksum rustc-demangle 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "a7f4dccf6f4891ebcc0c39f9b6eb1a83b9bf5d747cb439ec6fba4f3b977038af" "checksum rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7540fc8b0c49f096ee9c961cda096467dce8084bec6bdca2fc83895fd9b28cb8" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -"checksum rustyline 5.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b7d4ca3c9586d2c1f742284f032e328313ea55f3f60a3b0a17e2ca1a2bf9ae22" +"checksum rustyline 5.0.1 (git+https://github.com/kkawakam/rustyline.git)" = "" "checksum ryu 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c92464b447c0ee8c4fb3824ecc8383b81717b9f1e74ba2e72540aef7b9f82997" "checksum safemem 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e133ccc4f4d1cd4f89cc8a7ff618287d56dc7f638b8e38fc32c5fdcadc339dd5" "checksum same-file 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "585e8ddcedc187886a30fa705c47985c3fa88d06624095856b36ca0b82ff4421" diff --git a/README.md b/README.md index 3a989d14bb..60a093635c 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,7 @@ Nu adheres closely to a set of goals that make up its design philosophy. As feat | first amount | Show only the first number of rows | | 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 af81058723..ce01338c28 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)), @@ -160,6 +161,7 @@ pub async fn cli() -> Result<(), Box> { command("enter", Box::new(enter::enter)), 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 9366257a8d..7e683617ed 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 0000000000..ac3ab3c1c1 --- /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 0000000000..10bef6786a --- /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 1db0de12f1..c6af90fdc9 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())));