mirror of
https://github.com/nushell/nushell.git
synced 2024-12-22 23:23:12 +01:00
Add from_array and improve array viewing
This commit is contained in:
parent
7c4a4ec62e
commit
3d5395fdd5
6
Cargo.lock
generated
6
Cargo.lock
generated
@ -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)" = "<none>"
|
||||
"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"
|
||||
|
@ -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 |
|
||||
|
@ -147,6 +147,7 @@ pub async fn cli() -> Result<(), Box<dyn Error>> {
|
||||
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<dyn Error>> {
|
||||
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)),
|
||||
|
@ -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;
|
||||
|
14
src/commands/debug.rs
Normal file
14
src/commands/debug.rs
Normal file
@ -0,0 +1,14 @@
|
||||
use crate::errors::ShellError;
|
||||
use crate::prelude::*;
|
||||
|
||||
pub fn debug(args: CommandArgs, _registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
|
||||
let input = args.input;
|
||||
|
||||
Ok(input
|
||||
.values
|
||||
.map(|v| {
|
||||
println!("{:?}", v);
|
||||
ReturnSuccess::value(v)
|
||||
})
|
||||
.to_output_stream())
|
||||
}
|
21
src/commands/from_array.rs
Normal file
21
src/commands/from_array.rs
Normal file
@ -0,0 +1,21 @@
|
||||
use crate::object::Value;
|
||||
use crate::prelude::*;
|
||||
|
||||
pub fn from_array(
|
||||
args: CommandArgs,
|
||||
_registry: &CommandRegistry,
|
||||
) -> Result<OutputStream, ShellError> {
|
||||
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())
|
||||
}
|
@ -40,11 +40,17 @@ impl TableView {
|
||||
let mut entries = vec![];
|
||||
|
||||
for (idx, value) in values.iter().enumerate() {
|
||||
let mut row: Vec<String> = headers
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, d)| value.get_data(d).borrow().format_leaf(Some(&headers[i])))
|
||||
.collect();
|
||||
let mut row: Vec<String> = 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())));
|
||||
|
Loading…
Reference in New Issue
Block a user