mirror of
https://github.com/nushell/nushell.git
synced 2024-11-07 17:14:23 +01:00
Rename count
to length
(#3166)
* update docs to refer to length instead of count * rename count to length * change all occurrences of 'count' to 'length' in tests * format length command
This commit is contained in:
parent
6cf8df8685
commit
c13fe83784
@ -23,7 +23,6 @@ pub(crate) mod clip;
|
|||||||
pub(crate) mod compact;
|
pub(crate) mod compact;
|
||||||
pub(crate) mod config;
|
pub(crate) mod config;
|
||||||
pub(crate) mod constants;
|
pub(crate) mod constants;
|
||||||
pub(crate) mod count;
|
|
||||||
pub(crate) mod cp;
|
pub(crate) mod cp;
|
||||||
pub(crate) mod date;
|
pub(crate) mod date;
|
||||||
pub(crate) mod debug;
|
pub(crate) mod debug;
|
||||||
@ -72,6 +71,7 @@ pub(crate) mod insert;
|
|||||||
pub(crate) mod into_int;
|
pub(crate) mod into_int;
|
||||||
pub(crate) mod keep;
|
pub(crate) mod keep;
|
||||||
pub(crate) mod last;
|
pub(crate) mod last;
|
||||||
|
pub(crate) mod length;
|
||||||
pub(crate) mod let_;
|
pub(crate) mod let_;
|
||||||
pub(crate) mod let_env;
|
pub(crate) mod let_env;
|
||||||
pub(crate) mod lines;
|
pub(crate) mod lines;
|
||||||
@ -154,7 +154,6 @@ pub(crate) use compact::Compact;
|
|||||||
pub(crate) use config::{
|
pub(crate) use config::{
|
||||||
Config, ConfigClear, ConfigGet, ConfigLoad, ConfigPath, ConfigRemove, ConfigSet, ConfigSetInto,
|
Config, ConfigClear, ConfigGet, ConfigLoad, ConfigPath, ConfigRemove, ConfigSet, ConfigSetInto,
|
||||||
};
|
};
|
||||||
pub(crate) use count::Count;
|
|
||||||
pub(crate) use cp::Cpy;
|
pub(crate) use cp::Cpy;
|
||||||
pub(crate) use date::{Date, DateFormat, DateListTimeZone, DateNow, DateToTable, DateToTimeZone};
|
pub(crate) use date::{Date, DateFormat, DateListTimeZone, DateNow, DateToTable, DateToTimeZone};
|
||||||
pub(crate) use debug::Debug;
|
pub(crate) use debug::Debug;
|
||||||
@ -212,6 +211,7 @@ pub(crate) use insert::Command as Insert;
|
|||||||
pub(crate) use into_int::IntoInt;
|
pub(crate) use into_int::IntoInt;
|
||||||
pub(crate) use keep::{Keep, KeepUntil, KeepWhile};
|
pub(crate) use keep::{Keep, KeepUntil, KeepWhile};
|
||||||
pub(crate) use last::Last;
|
pub(crate) use last::Last;
|
||||||
|
pub(crate) use length::Length;
|
||||||
pub(crate) use let_::Let;
|
pub(crate) use let_::Let;
|
||||||
pub(crate) use let_env::LetEnv;
|
pub(crate) use let_env::LetEnv;
|
||||||
pub(crate) use lines::Lines;
|
pub(crate) use lines::Lines;
|
||||||
|
@ -57,7 +57,7 @@ pub fn create_default_context(interactive: bool) -> Result<EvaluationContext, Bo
|
|||||||
whole_stream_command(Sleep),
|
whole_stream_command(Sleep),
|
||||||
// Statistics
|
// Statistics
|
||||||
whole_stream_command(Size),
|
whole_stream_command(Size),
|
||||||
whole_stream_command(Count),
|
whole_stream_command(Length),
|
||||||
whole_stream_command(Benchmark),
|
whole_stream_command(Benchmark),
|
||||||
// Metadata
|
// Metadata
|
||||||
whole_stream_command(Tags),
|
whole_stream_command(Tags),
|
||||||
|
@ -4,21 +4,21 @@ use nu_engine::WholeStreamCommand;
|
|||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{Signature, UntaggedValue, Value};
|
use nu_protocol::{Signature, UntaggedValue, Value};
|
||||||
|
|
||||||
pub struct Count;
|
pub struct Length;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct CountArgs {
|
pub struct LengthArgs {
|
||||||
column: bool,
|
column: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl WholeStreamCommand for Count {
|
impl WholeStreamCommand for Length {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
"count"
|
"length"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn signature(&self) -> Signature {
|
fn signature(&self) -> Signature {
|
||||||
Signature::build("count").switch(
|
Signature::build("length").switch(
|
||||||
"column",
|
"column",
|
||||||
"Calculate number of columns in table",
|
"Calculate number of columns in table",
|
||||||
Some('c'),
|
Some('c'),
|
||||||
@ -31,10 +31,10 @@ impl WholeStreamCommand for Count {
|
|||||||
|
|
||||||
async fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
async fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let tag = args.call_info.name_tag.clone();
|
let tag = args.call_info.name_tag.clone();
|
||||||
let (CountArgs { column }, input) = args.process().await?;
|
let (LengthArgs { column }, input) = args.process().await?;
|
||||||
let rows: Vec<Value> = input.collect().await;
|
let rows: Vec<Value> = input.collect().await;
|
||||||
|
|
||||||
let count = if column {
|
let length = if column {
|
||||||
if rows.is_empty() {
|
if rows.is_empty() {
|
||||||
0
|
0
|
||||||
} else {
|
} else {
|
||||||
@ -42,8 +42,8 @@ impl WholeStreamCommand for Count {
|
|||||||
UntaggedValue::Row(dictionary) => dictionary.length(),
|
UntaggedValue::Row(dictionary) => dictionary.length(),
|
||||||
_ => {
|
_ => {
|
||||||
return Err(ShellError::labeled_error(
|
return Err(ShellError::labeled_error(
|
||||||
"Cannot obtain column count",
|
"Cannot obtain column length",
|
||||||
"cannot obtain column count",
|
"cannot obtain column length",
|
||||||
tag,
|
tag,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -53,19 +53,21 @@ impl WholeStreamCommand for Count {
|
|||||||
rows.len()
|
rows.len()
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(OutputStream::one(UntaggedValue::int(count).into_value(tag)))
|
Ok(OutputStream::one(
|
||||||
|
UntaggedValue::int(length).into_value(tag),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
vec![
|
vec![
|
||||||
Example {
|
Example {
|
||||||
description: "Count the number of entries in a list",
|
description: "Count the number of entries in a list",
|
||||||
example: "echo [1 2 3 4 5] | count",
|
example: "echo [1 2 3 4 5] | length",
|
||||||
result: Some(vec![UntaggedValue::int(5).into()]),
|
result: Some(vec![UntaggedValue::int(5).into()]),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Count the number of columns in the calendar table",
|
description: "Count the number of columns in the calendar table",
|
||||||
example: "cal | count -c",
|
example: "cal | length -c",
|
||||||
result: None,
|
result: None,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@ -74,13 +76,13 @@ impl WholeStreamCommand for Count {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::Count;
|
use super::Length;
|
||||||
use super::ShellError;
|
use super::ShellError;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn examples_work_as_expected() -> Result<(), ShellError> {
|
fn examples_work_as_expected() -> Result<(), ShellError> {
|
||||||
use crate::examples::test as test_examples;
|
use crate::examples::test as test_examples;
|
||||||
|
|
||||||
test_examples(Count {})
|
test_examples(Length {})
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -33,7 +33,7 @@ fn cal_friday_the_thirteenths_in_2015() {
|
|||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".", pipeline(
|
cwd: ".", pipeline(
|
||||||
r#"
|
r#"
|
||||||
cal --full-year 2015 | default friday 0 | where friday == 13 | count
|
cal --full-year 2015 | default friday 0 | where friday == 13 | length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ fn cal_rows_in_2020() {
|
|||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".", pipeline(
|
cwd: ".", pipeline(
|
||||||
r#"
|
r#"
|
||||||
cal --full-year 2020 | count
|
cal --full-year 2020 | length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ fn discards_rows_where_given_column_is_empty() {
|
|||||||
open los_tres_amigos.json
|
open los_tres_amigos.json
|
||||||
| get amigos
|
| get amigos
|
||||||
| compact rusty_luck
|
| compact rusty_luck
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ fn discards_empty_rows_by_default() {
|
|||||||
echo "[1,2,3,14,null]"
|
echo "[1,2,3,14,null]"
|
||||||
| from json
|
| from json
|
||||||
| compact
|
| compact
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ fn adds_row_data_if_column_missing() {
|
|||||||
| get amigos
|
| get amigos
|
||||||
| default rusty_luck 1
|
| default rusty_luck 1
|
||||||
| where rusty_luck == 1
|
| where rusty_luck == 1
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ fn columns() {
|
|||||||
]
|
]
|
||||||
| drop column
|
| drop column
|
||||||
| get
|
| get
|
||||||
| count
|
| length
|
||||||
"#)
|
"#)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ fn rows() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn more_rows_than_table_has() {
|
fn more_rows_than_table_has() {
|
||||||
let actual = nu!(cwd: ".", "date | drop 50 | count");
|
let actual = nu!(cwd: ".", "date | drop 50 | length");
|
||||||
|
|
||||||
assert_eq!(actual.out, "0");
|
assert_eq!(actual.out, "0");
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ fn reports_emptiness() {
|
|||||||
| get are_empty
|
| get are_empty
|
||||||
| empty? check
|
| empty? check
|
||||||
| where check
|
| where check
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ fn gets_first_rows_by_amount() {
|
|||||||
r#"
|
r#"
|
||||||
ls
|
ls
|
||||||
| first 3
|
| first 3
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ fn gets_all_rows_if_amount_higher_than_all_rows() {
|
|||||||
r#"
|
r#"
|
||||||
ls
|
ls
|
||||||
| first 99
|
| first 99
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ fn gets_first_row_when_no_amount_given() {
|
|||||||
r#"
|
r#"
|
||||||
ls
|
ls
|
||||||
| first
|
| first
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ fn flatten_row_column_explicitly() {
|
|||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: dirs.test(),
|
cwd: dirs.test(),
|
||||||
"open katz.json | flatten people | where name == Andres | count"
|
"open katz.json | flatten people | where name == Andres | length"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(actual.out, "1");
|
assert_eq!(actual.out, "1");
|
||||||
@ -105,7 +105,7 @@ fn flatten_row_columns_having_same_column_names_flats_separately() {
|
|||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: dirs.test(),
|
cwd: dirs.test(),
|
||||||
"open katz.json | flatten | flatten people city | get city_name | count"
|
"open katz.json | flatten | flatten people city | get city_name | length"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(actual.out, "4");
|
assert_eq!(actual.out, "4");
|
||||||
@ -139,7 +139,7 @@ fn flatten_table_columns_explicitly() {
|
|||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: dirs.test(),
|
cwd: dirs.test(),
|
||||||
"open katz.json | flatten city | where people.name == Katz | count"
|
"open katz.json | flatten city | where people.name == Katz | length"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(actual.out, "2");
|
assert_eq!(actual.out, "2");
|
||||||
|
@ -89,7 +89,7 @@ fn column_paths_are_either_double_quoted_or_regular_unquoted_words_separated_by_
|
|||||||
r#"
|
r#"
|
||||||
open sample.toml
|
open sample.toml
|
||||||
| get package."9999"
|
| get package."9999"
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ fn groups() {
|
|||||||
open los_tres_caballeros.csv
|
open los_tres_caballeros.csv
|
||||||
| group-by rusty_at
|
| group-by rusty_at
|
||||||
| get "10/11/2013"
|
| get "10/11/2013"
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
use nu_test_support::{nu, pipeline};
|
use nu_test_support::{nu, pipeline};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn help_commands_count() {
|
fn help_commands_length() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".", pipeline(
|
cwd: ".", pipeline(
|
||||||
r#"
|
r#"
|
||||||
help commands | count
|
help commands | length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -16,11 +16,11 @@ fn help_commands_count() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn help_generate_docs_count() {
|
fn help_generate_docs_length() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".", pipeline(
|
cwd: ".", pipeline(
|
||||||
r#"
|
r#"
|
||||||
help generate_docs | flatten | count
|
help generate_docs | flatten | length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ fn gets_last_rows_by_amount() {
|
|||||||
r#"
|
r#"
|
||||||
ls
|
ls
|
||||||
| last 3
|
| last 3
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ fn gets_last_row_when_no_amount_given() {
|
|||||||
r#"
|
r#"
|
||||||
ls
|
ls
|
||||||
| last
|
| last
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ fn requests_more_rows_than_table_has() {
|
|||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".", pipeline(
|
cwd: ".", pipeline(
|
||||||
r#"
|
r#"
|
||||||
date | last 50 | count
|
date | last 50 | length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
use nu_test_support::{nu, pipeline};
|
use nu_test_support::{nu, pipeline};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn count_columns_in_cal_table() {
|
fn length_columns_in_cal_table() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".", pipeline(
|
cwd: ".", pipeline(
|
||||||
r#"
|
r#"
|
||||||
cal | count -c
|
cal | length -c
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -13,11 +13,11 @@ fn count_columns_in_cal_table() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn count_columns_no_rows() {
|
fn length_columns_no_rows() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".", pipeline(
|
cwd: ".", pipeline(
|
||||||
r#"
|
r#"
|
||||||
echo [] | count -c
|
echo [] | length -c
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
@ -42,7 +42,7 @@ fn lines_multi_value_split() {
|
|||||||
open sample-simple.json
|
open sample-simple.json
|
||||||
| get first second
|
| get first second
|
||||||
| lines
|
| lines
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ fn lists_regular_files() {
|
|||||||
cwd: dirs.test(), pipeline(
|
cwd: dirs.test(), pipeline(
|
||||||
r#"
|
r#"
|
||||||
ls
|
ls
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ fn lists_regular_files_using_asterisk_wildcard() {
|
|||||||
cwd: dirs.test(), pipeline(
|
cwd: dirs.test(), pipeline(
|
||||||
r#"
|
r#"
|
||||||
ls *.txt
|
ls *.txt
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ fn lists_regular_files_using_question_mark_wildcard() {
|
|||||||
cwd: dirs.test(), pipeline(
|
cwd: dirs.test(), pipeline(
|
||||||
r#"
|
r#"
|
||||||
ls *.??.txt
|
ls *.??.txt
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -88,7 +88,7 @@ fn lists_all_files_in_directories_from_stream() {
|
|||||||
r#"
|
r#"
|
||||||
echo dir_a dir_b
|
echo dir_a dir_b
|
||||||
| each { ls $it }
|
| each { ls $it }
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -105,7 +105,7 @@ fn does_not_fail_if_glob_matches_empty_directory() {
|
|||||||
cwd: dirs.test(), pipeline(
|
cwd: dirs.test(), pipeline(
|
||||||
r#"
|
r#"
|
||||||
ls dir_a
|
ls dir_a
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -142,7 +142,7 @@ fn list_files_from_two_parents_up_using_multiple_dots() {
|
|||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: dirs.test().join("foo/bar"),
|
cwd: dirs.test().join("foo/bar"),
|
||||||
r#"
|
r#"
|
||||||
ls ... | count
|
ls ... | length
|
||||||
"#
|
"#
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -165,7 +165,7 @@ fn lists_hidden_file_when_explicitly_specified() {
|
|||||||
cwd: dirs.test(), pipeline(
|
cwd: dirs.test(), pipeline(
|
||||||
r#"
|
r#"
|
||||||
ls .testdotfile
|
ls .testdotfile
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -199,7 +199,7 @@ fn lists_all_hidden_files_when_glob_contains_dot() {
|
|||||||
cwd: dirs.test(), pipeline(
|
cwd: dirs.test(), pipeline(
|
||||||
r#"
|
r#"
|
||||||
ls **/.*
|
ls **/.*
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -236,7 +236,7 @@ fn lists_all_hidden_files_when_glob_does_not_contain_dot() {
|
|||||||
cwd: dirs.test(), pipeline(
|
cwd: dirs.test(), pipeline(
|
||||||
r#"
|
r#"
|
||||||
ls **/*
|
ls **/*
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -259,7 +259,7 @@ fn lists_files_including_starting_with_dot() {
|
|||||||
cwd: dirs.test(), pipeline(
|
cwd: dirs.test(), pipeline(
|
||||||
r#"
|
r#"
|
||||||
ls -a
|
ls -a
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ fn show_created_paths() {
|
|||||||
pipeline(
|
pipeline(
|
||||||
r#"
|
r#"
|
||||||
mkdir -s dir_1 dir_2 dir_3
|
mkdir -s dir_1 dir_2 dir_3
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@ mod autoenv_untrust;
|
|||||||
mod cal;
|
mod cal;
|
||||||
mod cd;
|
mod cd;
|
||||||
mod compact;
|
mod compact;
|
||||||
mod count;
|
|
||||||
mod cp;
|
mod cp;
|
||||||
mod def;
|
mod def;
|
||||||
mod default;
|
mod default;
|
||||||
@ -28,6 +27,7 @@ mod insert;
|
|||||||
mod into_int;
|
mod into_int;
|
||||||
mod keep;
|
mod keep;
|
||||||
mod last;
|
mod last;
|
||||||
|
mod length;
|
||||||
mod lines;
|
mod lines;
|
||||||
mod ls;
|
mod ls;
|
||||||
mod math;
|
mod math;
|
||||||
|
@ -28,7 +28,7 @@ fn selects_many_rows() {
|
|||||||
ls
|
ls
|
||||||
| get name
|
| get name
|
||||||
| nth 1 0
|
| nth 1 0
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ fn rolls_4_roll() {
|
|||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".", pipeline(
|
cwd: ".", pipeline(
|
||||||
r#"
|
r#"
|
||||||
random dice -d 4 -s 10 | count
|
random dice -d 4 -s 10 | length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ fn selects_some_rows() {
|
|||||||
ls
|
ls
|
||||||
| get name
|
| get name
|
||||||
| range 1..2
|
| range 1..2
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ fn changes_the_column_name() {
|
|||||||
| wrap name
|
| wrap name
|
||||||
| rename mosqueteros
|
| rename mosqueteros
|
||||||
| get mosqueteros
|
| get mosqueteros
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ fn keeps_remaining_original_names_given_less_new_names_than_total_original_names
|
|||||||
| default hit "arepa!"
|
| default hit "arepa!"
|
||||||
| rename mosqueteros
|
| rename mosqueteros
|
||||||
| get hit
|
| get hit
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ fn allows_if_given_unknown_column_name_is_missing() {
|
|||||||
[Yehuda Katz 10/11/2013 A]
|
[Yehuda Katz 10/11/2013 A]
|
||||||
]
|
]
|
||||||
| select rrusty_at first_name
|
| select rrusty_at first_name
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ fn splits() {
|
|||||||
| group-by rusty_at
|
| group-by rusty_at
|
||||||
| split-by type
|
| split-by type
|
||||||
| get A."10/11/2013"
|
| get A."10/11/2013"
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ fn to_row() {
|
|||||||
| lines
|
| lines
|
||||||
| str trim
|
| str trim
|
||||||
| split row ","
|
| split row ","
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ fn removes_duplicate_rows() {
|
|||||||
r#"
|
r#"
|
||||||
open los_tres_caballeros.csv
|
open los_tres_caballeros.csv
|
||||||
| uniq
|
| uniq
|
||||||
| count
|
| length
|
||||||
|
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
@ -52,7 +52,7 @@ fn uniq_values() {
|
|||||||
open los_tres_caballeros.csv
|
open los_tres_caballeros.csv
|
||||||
| select type
|
| select type
|
||||||
| uniq
|
| uniq
|
||||||
| count
|
| length
|
||||||
|
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
@ -117,7 +117,7 @@ fn nested_json_structures() {
|
|||||||
r#"
|
r#"
|
||||||
open nested_json_structures.json
|
open nested_json_structures.json
|
||||||
| uniq
|
| uniq
|
||||||
| count
|
| length
|
||||||
|
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
@ -133,7 +133,7 @@ fn uniq_when_keys_out_of_order() {
|
|||||||
echo '[{"a": "a", "b": [1,2,3]},{"b": [1,2,3], "a": "a"}]'
|
echo '[{"a": "a", "b": [1,2,3]},{"b": [1,2,3], "a": "a"}]'
|
||||||
| from json
|
| from json
|
||||||
| uniq
|
| uniq
|
||||||
| count
|
| length
|
||||||
|
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
@ -145,7 +145,7 @@ fn contains_operator() {
|
|||||||
| where table_name == strings
|
| where table_name == strings
|
||||||
| get table_values
|
| get table_values
|
||||||
| where x =~ ell
|
| where x =~ ell
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -158,7 +158,7 @@ fn contains_operator() {
|
|||||||
| where table_name == strings
|
| where table_name == strings
|
||||||
| get table_values
|
| get table_values
|
||||||
| where x !~ ell
|
| where x !~ ell
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -44,11 +44,11 @@ fn correct_precedence_alias_def_custom() {
|
|||||||
fn multiple_reports_for_alias_def_custom() {
|
fn multiple_reports_for_alias_def_custom() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".",
|
cwd: ".",
|
||||||
"def ls [] {echo def}; alias ls = echo alias; which -a ls | count"
|
"def ls [] {echo def}; alias ls = echo alias; which -a ls | length"
|
||||||
);
|
);
|
||||||
|
|
||||||
let count: i32 = actual.out.parse().unwrap();
|
let length: i32 = actual.out.parse().unwrap();
|
||||||
assert!(count >= 3);
|
assert!(length >= 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
// `get_aliases_with_name` and `get_custom_commands_with_name` don't return the correct count of
|
// `get_aliases_with_name` and `get_custom_commands_with_name` don't return the correct count of
|
||||||
@ -61,11 +61,11 @@ fn multiple_reports_for_alias_def_custom() {
|
|||||||
fn multiple_reports_of_multiple_alias() {
|
fn multiple_reports_of_multiple_alias() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".",
|
cwd: ".",
|
||||||
"alias xaz = echo alias1; def helper [] {alias xaz = echo alias2; which -a xaz}; helper | count"
|
"alias xaz = echo alias1; def helper [] {alias xaz = echo alias2; which -a xaz}; helper | length"
|
||||||
);
|
);
|
||||||
|
|
||||||
let count: i32 = actual.out.parse().unwrap();
|
let length: i32 = actual.out.parse().unwrap();
|
||||||
assert_eq!(count, 2);
|
assert_eq!(length, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[ignore]
|
#[ignore]
|
||||||
@ -73,11 +73,11 @@ fn multiple_reports_of_multiple_alias() {
|
|||||||
fn multiple_reports_of_multiple_defs() {
|
fn multiple_reports_of_multiple_defs() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".",
|
cwd: ".",
|
||||||
"def xaz [] {echo def1}; def helper [] { def xaz [] { echo def2 }; which -a xaz }; helper | count"
|
"def xaz [] {echo def1}; def helper [] { def xaz [] { echo def2 }; which -a xaz }; helper | length"
|
||||||
);
|
);
|
||||||
|
|
||||||
let count: i32 = actual.out.parse().unwrap();
|
let length: i32 = actual.out.parse().unwrap();
|
||||||
assert_eq!(count, 2);
|
assert_eq!(length, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Fails due to ParserScope::add_definition
|
//Fails due to ParserScope::add_definition
|
||||||
@ -88,9 +88,9 @@ fn multiple_reports_of_multiple_defs() {
|
|||||||
fn def_only_seen_once() {
|
fn def_only_seen_once() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".",
|
cwd: ".",
|
||||||
"def xaz [] {echo def1}; which -a xaz | count"
|
"def xaz [] {echo def1}; which -a xaz | length"
|
||||||
);
|
);
|
||||||
//count is 2. One custom_command (def) one built in ("wrongly" added)
|
//length is 2. One custom_command (def) one built in ("wrongly" added)
|
||||||
let count: i32 = actual.out.parse().unwrap();
|
let length: i32 = actual.out.parse().unwrap();
|
||||||
assert_eq!(count, 1);
|
assert_eq!(length, 1);
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@ fn infers_types() {
|
|||||||
r#"
|
r#"
|
||||||
open los_cuatro_mosqueteros.csv
|
open los_cuatro_mosqueteros.csv
|
||||||
| where rusty_luck > 0
|
| where rusty_luck > 0
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ fn from_csv_text_to_table() {
|
|||||||
open los_tres_caballeros.txt
|
open los_tres_caballeros.txt
|
||||||
| from csv
|
| from csv
|
||||||
| get rusty_luck
|
| get rusty_luck
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ fn from_csv_text_with_separator_to_table() {
|
|||||||
open los_tres_caballeros.txt
|
open los_tres_caballeros.txt
|
||||||
| from csv --separator ';'
|
| from csv --separator ';'
|
||||||
| get rusty_luck
|
| get rusty_luck
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -174,7 +174,7 @@ fn from_csv_text_with_tab_separator_to_table() {
|
|||||||
open los_tres_caballeros.txt
|
open los_tres_caballeros.txt
|
||||||
| from csv --separator '\t'
|
| from csv --separator '\t'
|
||||||
| get rusty_luck
|
| get rusty_luck
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -200,7 +200,7 @@ fn from_csv_text_skipping_headers_to_table() {
|
|||||||
open los_tres_amigos.txt
|
open los_tres_amigos.txt
|
||||||
| from csv --noheaders
|
| from csv --noheaders
|
||||||
| get Column3
|
| get Column3
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ fn infers_types() {
|
|||||||
r#"
|
r#"
|
||||||
open calendar.ics
|
open calendar.ics
|
||||||
| get events
|
| get events
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ fn from_json_text_to_table() {
|
|||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: dirs.test(),
|
cwd: dirs.test(),
|
||||||
"open katz.txt | from json | get katz | get rusty_luck | count "
|
"open katz.txt | from json | get katz | get rusty_luck | length "
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(actual.out, "4");
|
assert_eq!(actual.out, "4");
|
||||||
|
@ -97,7 +97,7 @@ fn from_tsv_text_to_table() {
|
|||||||
open los_tres_amigos.txt
|
open los_tres_amigos.txt
|
||||||
| from tsv
|
| from tsv
|
||||||
| get rusty_luck
|
| get rusty_luck
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -123,7 +123,7 @@ fn from_tsv_text_skipping_headers_to_table() {
|
|||||||
open los_tres_amigos.txt
|
open los_tres_amigos.txt
|
||||||
| from tsv --noheaders
|
| from tsv --noheaders
|
||||||
| get Column3
|
| get Column3
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ fn infers_types() {
|
|||||||
cwd: dirs.test(), pipeline(
|
cwd: dirs.test(), pipeline(
|
||||||
r#"
|
r#"
|
||||||
open contacts.vcf
|
open contacts.vcf
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# count
|
# length
|
||||||
|
|
||||||
Obtain the row or column count of a table.
|
Obtain the row or column count of a table.
|
||||||
|
|
||||||
@ -36,31 +36,31 @@ Obtain the row or column count of a table.
|
|||||||
────┴────────────────────┴──────┴──────────┴──────────────
|
────┴────────────────────┴──────┴──────────┴──────────────
|
||||||
```
|
```
|
||||||
|
|
||||||
By default, `count` will return the number of rows in a table
|
By default, `length` will return the number of rows in a table
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
> ls | count
|
> ls | length
|
||||||
20
|
20
|
||||||
```
|
```
|
||||||
|
|
||||||
The `-c` flag will produce a count of the columns in the table
|
The `-c` flag will produce a count of the columns in the table
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
> ls | count -c
|
> ls | length -c
|
||||||
4
|
4
|
||||||
```
|
```
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
> ls | where type == File | count
|
> ls | where type == File | length
|
||||||
11
|
11
|
||||||
```
|
```
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
> ls | where type == Dir | count
|
> ls | where type == Dir | length
|
||||||
9
|
9
|
||||||
```
|
```
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
> ls | where size > 2KB | count
|
> ls | where size > 2KB | length
|
||||||
4
|
4
|
||||||
```
|
```
|
4
tests/fixtures/formats/script_multiline.nu
vendored
4
tests/fixtures/formats/script_multiline.nu
vendored
@ -1,2 +1,2 @@
|
|||||||
echo [1 4] | count
|
echo [1 4] | length
|
||||||
echo [2 3 5] | count
|
echo [2 3 5] | length
|
||||||
|
@ -207,7 +207,7 @@ fn given_a_trusted_directory_with_entry_scripts_when_entering_a_subdirectory_ent
|
|||||||
let actual = Trusted::in_path(&dirs, || {
|
let actual = Trusted::in_path(&dirs, || {
|
||||||
nu!(cwd: dirs.test(), r#"
|
nu!(cwd: dirs.test(), r#"
|
||||||
cd time_to_cook_arepas
|
cd time_to_cook_arepas
|
||||||
ls | where name == "hello.txt" | count
|
ls | where name == "hello.txt" | length
|
||||||
"#)
|
"#)
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -238,7 +238,7 @@ fn given_a_trusted_directory_with_exit_scripts_when_entering_a_subdirectory_exit
|
|||||||
let actual = Trusted::in_path(&dirs, || {
|
let actual = Trusted::in_path(&dirs, || {
|
||||||
nu!(cwd: dirs.test(), r#"
|
nu!(cwd: dirs.test(), r#"
|
||||||
cd time_to_cook_arepas
|
cd time_to_cook_arepas
|
||||||
ls | where name == "bye.txt" | count
|
ls | where name == "bye.txt" | length
|
||||||
"#)
|
"#)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ mod it_evaluation {
|
|||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".",
|
cwd: ".",
|
||||||
r#"
|
r#"
|
||||||
nu --testbin repeater c 8197 | lines | count
|
nu --testbin repeater c 8197 | lines | length
|
||||||
"#
|
"#
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -165,7 +165,7 @@ mod stdin_evaluation {
|
|||||||
cwd: ".",
|
cwd: ".",
|
||||||
pipeline(r#"
|
pipeline(r#"
|
||||||
nu --testbin nonu "where's the nuline?"
|
nu --testbin nonu "where's the nuline?"
|
||||||
| count
|
| length
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user