mirror of
https://github.com/nushell/nushell
synced 2025-01-14 14:14:13 +00:00
Use 'table' on scripts and -c commands (#4377)
* Use 'table' on scripts and -c commands * Fix tests * Oops, missed a spot
This commit is contained in:
parent
659da3c4a4
commit
f9e1c4ef50
27 changed files with 125 additions and 77 deletions
|
@ -7,7 +7,7 @@ fn adds_a_row_to_the_end() {
|
||||||
r#"
|
r#"
|
||||||
echo [ "Andrés N. Robalino", "Jonathan Turner", "Yehuda Katz" ]
|
echo [ "Andrés N. Robalino", "Jonathan Turner", "Yehuda Katz" ]
|
||||||
| append "pollo loco"
|
| append "pollo loco"
|
||||||
| nth 3
|
| get 3
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ fn each_no_args_in_block() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
cwd: "tests/fixtures/formats", pipeline(
|
||||||
r#"
|
r#"
|
||||||
echo [[foo bar]; [a b] [c d] [e f]] | each {|i| $i | to json -r } | nth 1
|
echo [[foo bar]; [a b] [c d] [e f]] | each {|i| $i | to json -r } | get 1
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ fn each_implicit_it_in_block() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: "tests/fixtures/formats", pipeline(
|
cwd: "tests/fixtures/formats", pipeline(
|
||||||
r#"
|
r#"
|
||||||
echo [[foo bar]; [a b] [c d] [e f]] | each { nu --testbin cococo $it.foo }
|
echo [[foo bar]; [a b] [c d] [e f]] | each { nu --testbin cococo $it.foo } | str collect
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ fn find_with_list_search_with_string() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".", pipeline(
|
cwd: ".", pipeline(
|
||||||
r#"
|
r#"
|
||||||
[moe larry curly] | find moe
|
[moe larry curly] | find moe | get 0
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ fn find_with_list_search_with_number() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".", pipeline(
|
cwd: ".", pipeline(
|
||||||
r#"
|
r#"
|
||||||
[1 2 3 4 5] | find 3
|
[1 2 3 4 5] | find 3 | get 0
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ fn flatten_nested_tables() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".", pipeline(
|
cwd: ".", pipeline(
|
||||||
r#"
|
r#"
|
||||||
echo [[Andrés, Nicolás, Robalino]] | flatten | nth 1
|
echo [[Andrés, Nicolás, Robalino]] | flatten | get 1
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
|
@ -122,7 +122,7 @@ fn fetches_more_than_one_column_path() {
|
||||||
r#"
|
r#"
|
||||||
open sample.toml
|
open sample.toml
|
||||||
| get fortune_tellers.2.name fortune_tellers.0.name fortune_tellers.1.name
|
| get fortune_tellers.2.name fortune_tellers.0.name fortune_tellers.1.name
|
||||||
| nth 2
|
| get 2
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -222,7 +222,7 @@ fn errors_fetching_by_index_out_of_bounds() {
|
||||||
fn quoted_column_access() {
|
fn quoted_column_access() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: "tests/fixtures/formats",
|
cwd: "tests/fixtures/formats",
|
||||||
r#"echo '[{"foo bar": {"baz": 4}}]' | from json | get "foo bar".baz "#
|
r#"echo '[{"foo bar": {"baz": 4}}]' | from json | get "foo bar".baz.0 "#
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(actual.out, "4");
|
assert_eq!(actual.out, "4");
|
||||||
|
|
|
@ -6,7 +6,7 @@ use nu_test_support::{nu, pipeline};
|
||||||
fn gets_the_last_row() {
|
fn gets_the_last_row() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: "tests/fixtures/formats",
|
cwd: "tests/fixtures/formats",
|
||||||
"ls | sort-by name | last 1 | get name | str trim"
|
"ls | sort-by name | last 1 | get name.0 | str trim"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(actual.out, "utf16.ini");
|
assert_eq!(actual.out, "utf16.ini");
|
||||||
|
|
|
@ -11,7 +11,7 @@ fn lines() {
|
||||||
| skip 1
|
| skip 1
|
||||||
| first 1
|
| first 1
|
||||||
| split column "="
|
| split column "="
|
||||||
| get Column1
|
| get Column1.0
|
||||||
| str trim
|
| str trim
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
|
@ -13,7 +13,7 @@ fn selects_a_row() {
|
||||||
ls
|
ls
|
||||||
| sort-by name
|
| sort-by name
|
||||||
| nth 0
|
| nth 0
|
||||||
| get name
|
| get name.0
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ fn parses_csv() {
|
||||||
r#"
|
r#"
|
||||||
open nu.zion.csv
|
open nu.zion.csv
|
||||||
| where author == "Andres N. Robalino"
|
| where author == "Andres N. Robalino"
|
||||||
| get source
|
| get source.0
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ mod simple {
|
||||||
r#"
|
r#"
|
||||||
echo "{abc}123"
|
echo "{abc}123"
|
||||||
| parse "{{abc}{name}"
|
| parse "{{abc}{name}"
|
||||||
| get name
|
| get name.0
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ mod simple {
|
||||||
r#"
|
r#"
|
||||||
echo "(abc)123"
|
echo "(abc)123"
|
||||||
| parse "(abc){name}"
|
| parse "(abc){name}"
|
||||||
| get name
|
| get name.0
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ mod simple {
|
||||||
echo ["1:INFO:component:all is well" "2:ERROR::something bad happened"]
|
echo ["1:INFO:component:all is well" "2:ERROR::something bad happened"]
|
||||||
| parse "{timestamp}:{level}:{tag}:{entry}"
|
| parse "{timestamp}:{level}:{tag}:{entry}"
|
||||||
| get entry
|
| get entry
|
||||||
| nth 1
|
| get 1
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ mod regex {
|
||||||
r#"
|
r#"
|
||||||
open nushell_git_log_oneline.txt
|
open nushell_git_log_oneline.txt
|
||||||
| parse --regex "(?P<Hash>\w+) (?P<Message>.+) \(#(?P<PR>\d+)\)"
|
| parse --regex "(?P<Hash>\w+) (?P<Message>.+) \(#(?P<PR>\d+)\)"
|
||||||
| nth 1
|
| get 1
|
||||||
| get PR
|
| get PR
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
@ -144,7 +144,7 @@ mod regex {
|
||||||
r#"
|
r#"
|
||||||
open nushell_git_log_oneline.txt
|
open nushell_git_log_oneline.txt
|
||||||
| parse --regex "(\w+) (.+) \(#(\d+)\)"
|
| parse --regex "(\w+) (.+) \(#(\d+)\)"
|
||||||
| nth 1
|
| get 1
|
||||||
| get Capture1
|
| get Capture1
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
@ -163,7 +163,7 @@ mod regex {
|
||||||
r#"
|
r#"
|
||||||
open nushell_git_log_oneline.txt
|
open nushell_git_log_oneline.txt
|
||||||
| parse --regex "(?P<Hash>\w+) (.+) \(#(?P<PR>\d+)\)"
|
| parse --regex "(?P<Hash>\w+) (.+) \(#(?P<PR>\d+)\)"
|
||||||
| nth 1
|
| get 1
|
||||||
| get Capture2
|
| get Capture2
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
|
@ -9,7 +9,7 @@ fn returns_path_joined_with_column_path() {
|
||||||
r#"
|
r#"
|
||||||
echo [ [name]; [eggs] ]
|
echo [ [name]; [eggs] ]
|
||||||
| path join spam.txt -c [ name ]
|
| path join spam.txt -c [ name ]
|
||||||
| get name
|
| get name.0
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
|
@ -107,7 +107,7 @@ fn parses_column_path_extension() {
|
||||||
echo [[home, barn]; ['home/viking/spam.txt', 'barn/cow/moo.png']]
|
echo [[home, barn]; ['home/viking/spam.txt', 'barn/cow/moo.png']]
|
||||||
| path parse -c [ home barn ]
|
| path parse -c [ home barn ]
|
||||||
| get barn
|
| get barn
|
||||||
| get extension
|
| get extension.0
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ fn splits_correctly_single_path() {
|
||||||
'home/viking/spam.txt'
|
'home/viking/spam.txt'
|
||||||
| path split
|
| path split
|
||||||
| last
|
| last
|
||||||
|
| get 0
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ fn adds_a_row_to_the_beginning() {
|
||||||
open los_tres_caballeros.txt
|
open los_tres_caballeros.txt
|
||||||
| lines
|
| lines
|
||||||
| prepend "pollo loco"
|
| prepend "pollo loco"
|
||||||
| nth 0
|
| get 0
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ fn selects_a_row() {
|
||||||
ls
|
ls
|
||||||
| sort-by name
|
| sort-by name
|
||||||
| range 0..0
|
| range 0..0
|
||||||
| get name
|
| get name.0
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ fn regular_columns() {
|
||||||
[Yehuda Katz 10/11/2013 A]
|
[Yehuda Katz 10/11/2013 A]
|
||||||
]
|
]
|
||||||
| select rusty_at last_name
|
| select rusty_at last_name
|
||||||
| nth 0
|
| get 0
|
||||||
| get last_name
|
| get last_name
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
|
@ -4,7 +4,7 @@ use nu_test_support::nu;
|
||||||
fn which_ls() {
|
fn which_ls() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".",
|
cwd: ".",
|
||||||
"which ls | get path | str trim"
|
"which ls | get path.0 | str trim"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(actual.out, "Nushell built-in command");
|
assert_eq!(actual.out, "Nushell built-in command");
|
||||||
|
@ -14,7 +14,7 @@ fn which_ls() {
|
||||||
fn which_alias_ls() {
|
fn which_alias_ls() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".",
|
cwd: ".",
|
||||||
"alias ls = ls -a; which ls | get path | str trim"
|
"alias ls = ls -a; which ls | get path.0 | str trim"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(actual.out, "Nushell alias: ls -a");
|
assert_eq!(actual.out, "Nushell alias: ls -a");
|
||||||
|
@ -24,7 +24,7 @@ fn which_alias_ls() {
|
||||||
fn which_def_ls() {
|
fn which_def_ls() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".",
|
cwd: ".",
|
||||||
"def ls [] {echo def}; which ls | get path | str trim"
|
"def ls [] {echo def}; which ls | get path.0 | str trim"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(actual.out, "Nushell custom command");
|
assert_eq!(actual.out, "Nushell custom command");
|
||||||
|
@ -34,7 +34,7 @@ fn which_def_ls() {
|
||||||
fn correct_precedence_alias_def_custom() {
|
fn correct_precedence_alias_def_custom() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".",
|
cwd: ".",
|
||||||
"def ls [] {echo def}; alias ls = echo alias; which ls | get path | str trim"
|
"def ls [] {echo def}; alias ls = echo alias; which ls | get path.0 | str trim"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(actual.out, "Nushell alias: echo alias");
|
assert_eq!(actual.out, "Nushell alias: echo alias");
|
||||||
|
|
|
@ -22,7 +22,7 @@ fn wrap_rows_into_a_row() {
|
||||||
| from csv
|
| from csv
|
||||||
| wrap caballeros
|
| wrap caballeros
|
||||||
| get caballeros
|
| get caballeros
|
||||||
| nth 0
|
| get 0
|
||||||
| get last_name
|
| get last_name
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
@ -51,7 +51,7 @@ fn wrap_rows_into_a_table() {
|
||||||
| from csv
|
| from csv
|
||||||
| get last_name
|
| get last_name
|
||||||
| wrap caballero
|
| wrap caballero
|
||||||
| nth 2
|
| get 2
|
||||||
| get caballero
|
| get caballero
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
|
@ -62,7 +62,7 @@ fn from_json_text_recognizing_objects_independently_to_table() {
|
||||||
open katz.txt
|
open katz.txt
|
||||||
| from json -o
|
| from json -o
|
||||||
| where name == "GorbyPuff"
|
| where name == "GorbyPuff"
|
||||||
| get rusty_luck
|
| get rusty_luck.0
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ fn table_to_json_text() {
|
||||||
| select name
|
| select name
|
||||||
| to json
|
| to json
|
||||||
| from json
|
| from json
|
||||||
| nth 0
|
| get 0
|
||||||
| get name
|
| get name
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
|
@ -7,7 +7,7 @@ fn from_ods_file_to_table() {
|
||||||
r#"
|
r#"
|
||||||
open sample_data.ods
|
open sample_data.ods
|
||||||
| get SalesOrders
|
| get SalesOrders
|
||||||
| nth 4
|
| get 4
|
||||||
| get Column2
|
| get Column2
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
|
@ -20,7 +20,7 @@ fn from_ssv_text_to_table() {
|
||||||
r#"
|
r#"
|
||||||
open oc_get_svc.txt
|
open oc_get_svc.txt
|
||||||
| from ssv
|
| from ssv
|
||||||
| nth 0
|
| get 0
|
||||||
| get IP
|
| get IP
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
@ -47,7 +47,7 @@ fn from_ssv_text_to_table_with_separator_specified() {
|
||||||
r#"
|
r#"
|
||||||
open oc_get_svc.txt
|
open oc_get_svc.txt
|
||||||
| from ssv --minimum-spaces 3
|
| from ssv --minimum-spaces 3
|
||||||
| nth 0
|
| get 0
|
||||||
| get IP
|
| get IP
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
|
@ -7,7 +7,7 @@ fn from_excel_file_to_table() {
|
||||||
r#"
|
r#"
|
||||||
open sample_data.xlsx
|
open sample_data.xlsx
|
||||||
| get SalesOrders
|
| get SalesOrders
|
||||||
| nth 4
|
| get 4
|
||||||
| get Column2
|
| get Column2
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
|
@ -112,16 +112,7 @@ pub(crate) fn evaluate(
|
||||||
|
|
||||||
match eval_block(engine_state, &mut stack, &block, input) {
|
match eval_block(engine_state, &mut stack, &block, input) {
|
||||||
Ok(pipeline_data) => {
|
Ok(pipeline_data) => {
|
||||||
for item in pipeline_data {
|
crate::eval_file::print_table_or_error(engine_state, &mut stack, pipeline_data, &config)
|
||||||
if let Value::Error { error } = item {
|
|
||||||
let working_set = StateWorkingSet::new(engine_state);
|
|
||||||
|
|
||||||
report_error(&working_set, &error);
|
|
||||||
|
|
||||||
std::process::exit(1);
|
|
||||||
}
|
|
||||||
println!("{}", item.into_string("\n", &config));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
let working_set = StateWorkingSet::new(engine_state);
|
let working_set = StateWorkingSet::new(engine_state);
|
||||||
|
|
|
@ -3,10 +3,11 @@ use miette::{IntoDiagnostic, Result};
|
||||||
use nu_engine::{convert_env_values, eval_block};
|
use nu_engine::{convert_env_values, eval_block};
|
||||||
use nu_parser::parse;
|
use nu_parser::parse;
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
engine::{EngineState, StateDelta, StateWorkingSet},
|
ast::Call,
|
||||||
|
engine::{EngineState, Stack, StateDelta, StateWorkingSet},
|
||||||
Config, PipelineData, Span, Value, CONFIG_VARIABLE_ID,
|
Config, PipelineData, Span, Value, CONFIG_VARIABLE_ID,
|
||||||
};
|
};
|
||||||
use std::path::PathBuf;
|
use std::{io::Write, path::PathBuf};
|
||||||
|
|
||||||
use crate::utils::{gather_parent_env_vars, report_error};
|
use crate::utils::{gather_parent_env_vars, report_error};
|
||||||
|
|
||||||
|
@ -89,16 +90,7 @@ pub(crate) fn evaluate(
|
||||||
// We don't have a main, so evaluate the whole file
|
// We don't have a main, so evaluate the whole file
|
||||||
match eval_block(engine_state, &mut stack, &block, input) {
|
match eval_block(engine_state, &mut stack, &block, input) {
|
||||||
Ok(pipeline_data) => {
|
Ok(pipeline_data) => {
|
||||||
for item in pipeline_data {
|
print_table_or_error(engine_state, &mut stack, pipeline_data, &config)
|
||||||
if let Value::Error { error } = item {
|
|
||||||
let working_set = StateWorkingSet::new(engine_state);
|
|
||||||
|
|
||||||
report_error(&working_set, &error);
|
|
||||||
|
|
||||||
std::process::exit(1);
|
|
||||||
}
|
|
||||||
println!("{}", item.into_string("\n", &config));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
let working_set = StateWorkingSet::new(engine_state);
|
let working_set = StateWorkingSet::new(engine_state);
|
||||||
|
@ -131,16 +123,7 @@ pub(crate) fn evaluate(
|
||||||
|
|
||||||
match eval_block(engine_state, &mut stack, &block, input) {
|
match eval_block(engine_state, &mut stack, &block, input) {
|
||||||
Ok(pipeline_data) => {
|
Ok(pipeline_data) => {
|
||||||
for item in pipeline_data {
|
print_table_or_error(engine_state, &mut stack, pipeline_data, &config)
|
||||||
if let Value::Error { error } = item {
|
|
||||||
let working_set = StateWorkingSet::new(engine_state);
|
|
||||||
|
|
||||||
report_error(&working_set, &error);
|
|
||||||
|
|
||||||
std::process::exit(1);
|
|
||||||
}
|
|
||||||
println!("{}", item.into_string("\n", &config));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
let working_set = StateWorkingSet::new(engine_state);
|
let working_set = StateWorkingSet::new(engine_state);
|
||||||
|
@ -154,3 +137,73 @@ pub(crate) fn evaluate(
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn print_table_or_error(
|
||||||
|
engine_state: &EngineState,
|
||||||
|
stack: &mut Stack,
|
||||||
|
pipeline_data: PipelineData,
|
||||||
|
config: &Config,
|
||||||
|
) {
|
||||||
|
match engine_state.find_decl("table".as_bytes()) {
|
||||||
|
Some(decl_id) => {
|
||||||
|
let table = engine_state.get_decl(decl_id).run(
|
||||||
|
engine_state,
|
||||||
|
stack,
|
||||||
|
&Call::new(Span::new(0, 0)),
|
||||||
|
pipeline_data,
|
||||||
|
);
|
||||||
|
|
||||||
|
match table {
|
||||||
|
Ok(table) => {
|
||||||
|
for item in table {
|
||||||
|
let stdout = std::io::stdout();
|
||||||
|
|
||||||
|
if let Value::Error { error } = item {
|
||||||
|
let working_set = StateWorkingSet::new(engine_state);
|
||||||
|
|
||||||
|
report_error(&working_set, &error);
|
||||||
|
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut out = item.into_string("\n", config);
|
||||||
|
out.push('\n');
|
||||||
|
|
||||||
|
match stdout.lock().write_all(out.as_bytes()) {
|
||||||
|
Ok(_) => (),
|
||||||
|
Err(err) => eprintln!("{}", err),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(error) => {
|
||||||
|
let working_set = StateWorkingSet::new(engine_state);
|
||||||
|
|
||||||
|
report_error(&working_set, &error);
|
||||||
|
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
for item in pipeline_data {
|
||||||
|
let stdout = std::io::stdout();
|
||||||
|
|
||||||
|
if let Value::Error { error } = item {
|
||||||
|
let working_set = StateWorkingSet::new(engine_state);
|
||||||
|
|
||||||
|
report_error(&working_set, &error);
|
||||||
|
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut out = item.into_string("\n", config);
|
||||||
|
out.push('\n');
|
||||||
|
|
||||||
|
match stdout.lock().write_all(out.as_bytes()) {
|
||||||
|
Ok(_) => (),
|
||||||
|
Err(err) => eprintln!("{}", err),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -22,7 +22,10 @@ fn cell_path_var2() -> TestResult {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn flatten_simple_list() -> TestResult {
|
fn flatten_simple_list() -> TestResult {
|
||||||
run_test("[[N, u, s, h, e, l, l]] | flatten", "N\nu\ns\nh\ne\nl\nl")
|
run_test(
|
||||||
|
"[[N, u, s, h, e, l, l]] | flatten | str collect (char nl)",
|
||||||
|
"N\nu\ns\nh\ne\nl\nl",
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -33,7 +36,7 @@ fn flatten_get_simple_list() -> TestResult {
|
||||||
#[test]
|
#[test]
|
||||||
fn flatten_table_get() -> TestResult {
|
fn flatten_table_get() -> TestResult {
|
||||||
run_test(
|
run_test(
|
||||||
"[[origin, people]; [Ecuador, ([[name, meal]; ['Andres', 'arepa']])]] | flatten | get meal",
|
"[[origin, people]; [Ecuador, ([[name, meal]; ['Andres', 'arepa']])]] | flatten | get meal.0",
|
||||||
"arepa",
|
"arepa",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -41,7 +44,7 @@ fn flatten_table_get() -> TestResult {
|
||||||
#[test]
|
#[test]
|
||||||
fn flatten_table_column_get_last() -> TestResult {
|
fn flatten_table_column_get_last() -> TestResult {
|
||||||
run_test(
|
run_test(
|
||||||
"[[origin, crate, versions]; [World, ([[name]; ['nu-cli']]), ['0.21', '0.22']]] | flatten versions | last | get versions",
|
"[[origin, crate, versions]; [World, ([[name]; ['nu-cli']]), ['0.21', '0.22']]] | flatten versions | last | get versions.0",
|
||||||
"0.22",
|
"0.22",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -56,7 +59,7 @@ fn get_table_columns_1() -> TestResult {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn get_table_columns_2() -> TestResult {
|
fn get_table_columns_2() -> TestResult {
|
||||||
run_test("[[name, age, grade]; [paul,21,a]] | columns | nth 1", "age")
|
run_test("[[name, age, grade]; [paul,21,a]] | columns | get 1", "age")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -111,7 +111,7 @@ mod it_evaluation {
|
||||||
ls
|
ls
|
||||||
| sort-by name
|
| sort-by name
|
||||||
| get name
|
| get name
|
||||||
| each { nu --testbin cococo $it | lines }
|
| each { nu --testbin cococo $it }
|
||||||
| get 1
|
| get 1
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
@ -136,7 +136,7 @@ mod it_evaluation {
|
||||||
r#"
|
r#"
|
||||||
open nu_candies.txt
|
open nu_candies.txt
|
||||||
| lines
|
| lines
|
||||||
| each { nu --testbin chop $it | lines}
|
| each { nu --testbin chop $it}
|
||||||
| get 1
|
| get 1
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
|
@ -22,7 +22,7 @@ fn takes_rows_of_nu_value_strings_and_pipes_it_to_stdin_of_external() {
|
||||||
r#"
|
r#"
|
||||||
open nu_times.csv
|
open nu_times.csv
|
||||||
| get origin
|
| get origin
|
||||||
| each { ^echo $it | nu --testbin chop | lines }
|
| each { ^echo $it | nu --testbin chop }
|
||||||
| get 2
|
| get 2
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
@ -102,7 +102,7 @@ fn subexpression_handles_dot() {
|
||||||
r#"
|
r#"
|
||||||
echo (open nu_times.csv)
|
echo (open nu_times.csv)
|
||||||
| get name
|
| get name
|
||||||
| each { nu --testbin chop $it | lines }
|
| each { nu --testbin chop $it }
|
||||||
| get 3
|
| get 3
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
@ -128,7 +128,7 @@ fn string_interpolation_with_it_column_path() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".",
|
cwd: ".",
|
||||||
r#"
|
r#"
|
||||||
echo [[name]; [sammie]] | each { echo $"($it.name)" }
|
echo [[name]; [sammie]] | each { echo $"($it.name)" } | get 0
|
||||||
"#
|
"#
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -819,7 +819,7 @@ fn table_literals1() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".",
|
cwd: ".",
|
||||||
r#"
|
r#"
|
||||||
echo [[name age]; [foo 13]] | get age
|
echo [[name age]; [foo 13]] | get age.0
|
||||||
"#
|
"#
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue