From 088901b24fed2814a8dc830e23ea60f56faa99fb Mon Sep 17 00:00:00 2001 From: Joseph T Lyons Date: Fri, 19 Jun 2020 19:20:25 -0400 Subject: [PATCH] Rename average to avg --- crates/nu-cli/src/commands/math/{average.rs => avg.rs} | 6 +++--- crates/nu-cli/src/commands/math/command.rs | 2 +- crates/nu-cli/src/commands/math/mod.rs | 4 ++-- .../nu-cli/tests/commands/math/{average.rs => avg.rs} | 4 ++-- crates/nu-cli/tests/commands/math/mod.rs | 2 +- docs/commands/math.md | 10 +++++----- 6 files changed, 14 insertions(+), 14 deletions(-) rename crates/nu-cli/src/commands/math/{average.rs => avg.rs} (96%) rename crates/nu-cli/tests/commands/math/{average.rs => avg.rs} (89%) diff --git a/crates/nu-cli/src/commands/math/average.rs b/crates/nu-cli/src/commands/math/avg.rs similarity index 96% rename from crates/nu-cli/src/commands/math/average.rs rename to crates/nu-cli/src/commands/math/avg.rs index ecb111cd46..23d2357d51 100644 --- a/crates/nu-cli/src/commands/math/average.rs +++ b/crates/nu-cli/src/commands/math/avg.rs @@ -14,11 +14,11 @@ pub struct SubCommand; #[async_trait] impl WholeStreamCommand for SubCommand { fn name(&self) -> &str { - "math average" + "math avg" } fn signature(&self) -> Signature { - Signature::build("math average") + Signature::build("math avg") } fn usage(&self) -> &str { @@ -49,7 +49,7 @@ impl WholeStreamCommand for SubCommand { fn examples(&self) -> Vec { vec![Example { description: "Get the average of a list of numbers", - example: "echo [-50 100.0 25] | math average", + example: "echo [-50 100.0 25] | math avg", result: Some(vec![UntaggedValue::decimal(25).into()]), }] } diff --git a/crates/nu-cli/src/commands/math/command.rs b/crates/nu-cli/src/commands/math/command.rs index b6609754c0..266b560203 100644 --- a/crates/nu-cli/src/commands/math/command.rs +++ b/crates/nu-cli/src/commands/math/command.rs @@ -35,7 +35,7 @@ impl WholeStreamCommand for Command { mod tests { use super::*; use crate::commands::math::{ - average::average, max::maximum, min::minimum, sum::summation, utils::MathFunction, + avg::average, max::maximum, min::minimum, sum::summation, utils::MathFunction, }; use nu_plugin::test_helpers::value::{decimal, int}; use nu_protocol::Value; diff --git a/crates/nu-cli/src/commands/math/mod.rs b/crates/nu-cli/src/commands/math/mod.rs index 399416fb65..f30ada16c5 100644 --- a/crates/nu-cli/src/commands/math/mod.rs +++ b/crates/nu-cli/src/commands/math/mod.rs @@ -1,4 +1,4 @@ -pub mod average; +pub mod avg; pub mod command; pub mod max; pub mod median; @@ -6,7 +6,7 @@ pub mod min; pub mod sum; pub mod utils; -pub use average::SubCommand as MathAverage; +pub use avg::SubCommand as MathAverage; pub use command::Command as Math; pub use max::SubCommand as MathMaximum; pub use median::SubCommand as MathMedian; diff --git a/crates/nu-cli/tests/commands/math/average.rs b/crates/nu-cli/tests/commands/math/avg.rs similarity index 89% rename from crates/nu-cli/tests/commands/math/average.rs rename to crates/nu-cli/tests/commands/math/avg.rs index caa586ff7c..c139e6aba6 100644 --- a/crates/nu-cli/tests/commands/math/average.rs +++ b/crates/nu-cli/tests/commands/math/avg.rs @@ -7,7 +7,7 @@ fn can_average_numbers() { r#" open sgml_description.json | get glossary.GlossDiv.GlossList.GlossEntry.Sections - | math average + | math avg | echo $it "# )); @@ -19,7 +19,7 @@ fn can_average_numbers() { fn can_average_bytes() { let actual = nu!( cwd: "tests/fixtures/formats", - "ls | sort-by name | skip 1 | first 2 | get size | math average | format \"{$it}\" | echo $it" + "ls | sort-by name | skip 1 | first 2 | get size | math avg | format \"{$it}\" | echo $it" ); assert_eq!(actual.out, "1.6 KB"); diff --git a/crates/nu-cli/tests/commands/math/mod.rs b/crates/nu-cli/tests/commands/math/mod.rs index ff682ab3ad..78c591c90a 100644 --- a/crates/nu-cli/tests/commands/math/mod.rs +++ b/crates/nu-cli/tests/commands/math/mod.rs @@ -1,4 +1,4 @@ -mod average; +mod avg; mod median; use nu_test_support::{nu, pipeline}; diff --git a/docs/commands/math.md b/docs/commands/math.md index fa61dd3797..4c2528000f 100644 --- a/docs/commands/math.md +++ b/docs/commands/math.md @@ -3,7 +3,7 @@ Mathematical functions that generally only operate on a list of numbers (integers, decimals, bytes) and tables. Currently the following functions are implemented: -* `math average`: Finds the average of a list of numbers or tables +* `math avg`: Finds the average of a list of numbers or tables * `math min`: Finds the minimum within a list of numbers or tables * `math max`: Finds the maximum within a list of numbers or tables * `math sum`: Finds the sum of a list of numbers or tables @@ -44,7 +44,7 @@ To get the average of the file sizes in a directory, simply pipe the size column ``` ```shell -> ls | get size | math average +> ls | get size | math avg ───┬──────── 0 │ 7.2 KB ───┴──────── @@ -108,7 +108,7 @@ To get the average of the file sizes in a directory, simply pipe the size column ``` ```shell -> pwd | split row / | size | math average +> pwd | split row / | size | math avg ────────────┬──────── lines │ 0.0000 words │ 1.0000 @@ -129,7 +129,7 @@ To get the sum of the characters that make up your present working directory. `math` functions are aggregation functions so empty lists are invalid ```shell -> echo [] | math average +> echo [] | math avg error: Error: Unexpected: Cannot perform aggregate math operation on empty data ``` @@ -137,6 +137,6 @@ Note `math` functions only work on list of numbers (integers, decimals, bytes) a then unexpected results can occur. ```shell -> echo [1 2 a ] | math average +> echo [1 2 a ] | math avg 0 ```