From 942c66a9f30a89085e92df0807b36281d888a059 Mon Sep 17 00:00:00 2001 From: Michael Angerman <1809991+stormasm@users.noreply.github.com> Date: Tue, 11 Jul 2023 11:23:39 -0700 Subject: [PATCH] cratification: part II of the math commands to nu-cmd-extra (#9657) The following math commands are being moved to nu-cmd-extra * cos * cosh * egamma * phi * pi * sin * sinh * tan * tanh * tau For now I think we have most of the obvious commands moved over based on @sholderbach this should cover moving the "high school" commands.. >>Yeah I think this rough separation into "high school" math in extra and "middle school"/"programmer" math in the core makes a ton of sense. And to reference the @fdncred list from https://github.com/nushell/nushell/pull/9647#issuecomment-1629498812 --- crates/nu-cmd-extra/src/example_test.rs | 4 ++++ .../src/extra}/math/cos.rs | 0 .../src/extra}/math/cosh.rs | 0 .../src/extra}/math/egamma.rs | 0 crates/nu-cmd-extra/src/extra/math/mod.rs | 24 +++++++++++++++++++ .../src/extra}/math/phi.rs | 0 .../src => nu-cmd-extra/src/extra}/math/pi.rs | 0 .../src/extra}/math/sin.rs | 0 .../src/extra}/math/sinh.rs | 0 .../src/extra}/math/tan.rs | 0 .../src/extra}/math/tanh.rs | 0 .../src/extra}/math/tau.rs | 0 crates/nu-cmd-extra/src/extra/mod.rs | 22 ++++++++++++++++- crates/nu-command/src/default_context.rs | 8 ------- crates/nu-command/src/example_test.rs | 7 +++--- crates/nu-command/src/math/mod.rs | 21 ---------------- 16 files changed, 52 insertions(+), 34 deletions(-) rename crates/{nu-command/src => nu-cmd-extra/src/extra}/math/cos.rs (100%) rename crates/{nu-command/src => nu-cmd-extra/src/extra}/math/cosh.rs (100%) rename crates/{nu-command/src => nu-cmd-extra/src/extra}/math/egamma.rs (100%) rename crates/{nu-command/src => nu-cmd-extra/src/extra}/math/phi.rs (100%) rename crates/{nu-command/src => nu-cmd-extra/src/extra}/math/pi.rs (100%) rename crates/{nu-command/src => nu-cmd-extra/src/extra}/math/sin.rs (100%) rename crates/{nu-command/src => nu-cmd-extra/src/extra}/math/sinh.rs (100%) rename crates/{nu-command/src => nu-cmd-extra/src/extra}/math/tan.rs (100%) rename crates/{nu-command/src => nu-cmd-extra/src/extra}/math/tanh.rs (100%) rename crates/{nu-command/src => nu-cmd-extra/src/extra}/math/tau.rs (100%) diff --git a/crates/nu-cmd-extra/src/example_test.rs b/crates/nu-cmd-extra/src/example_test.rs index 710486a79..9c352b108 100644 --- a/crates/nu-cmd-extra/src/example_test.rs +++ b/crates/nu-cmd-extra/src/example_test.rs @@ -15,6 +15,7 @@ mod test_examples { check_example_input_and_output_types_match_command_signature, }; + use crate::MathPi; use nu_protocol::{ engine::{Command, EngineState, StateWorkingSet}, Type, @@ -63,6 +64,9 @@ mod test_examples { working_set.add_decl(Box::new(nu_command::Enumerate)); working_set.add_decl(Box::new(nu_cmd_lang::If)); + // math commands + working_set.add_decl(Box::new(MathPi)); + working_set.add_decl(Box::new(nu_command::MathRound)); // Adding the command that is being tested to the working set working_set.add_decl(cmd); diff --git a/crates/nu-command/src/math/cos.rs b/crates/nu-cmd-extra/src/extra/math/cos.rs similarity index 100% rename from crates/nu-command/src/math/cos.rs rename to crates/nu-cmd-extra/src/extra/math/cos.rs diff --git a/crates/nu-command/src/math/cosh.rs b/crates/nu-cmd-extra/src/extra/math/cosh.rs similarity index 100% rename from crates/nu-command/src/math/cosh.rs rename to crates/nu-cmd-extra/src/extra/math/cosh.rs diff --git a/crates/nu-command/src/math/egamma.rs b/crates/nu-cmd-extra/src/extra/math/egamma.rs similarity index 100% rename from crates/nu-command/src/math/egamma.rs rename to crates/nu-cmd-extra/src/extra/math/egamma.rs diff --git a/crates/nu-cmd-extra/src/extra/math/mod.rs b/crates/nu-cmd-extra/src/extra/math/mod.rs index 411f89989..d2a02de1a 100644 --- a/crates/nu-cmd-extra/src/extra/math/mod.rs +++ b/crates/nu-cmd-extra/src/extra/math/mod.rs @@ -1,3 +1,15 @@ +mod cos; +mod cosh; +mod sin; +mod sinh; +mod tan; +mod tanh; + +mod egamma; +mod phi; +mod pi; +mod tau; + mod arccos; mod arccosh; mod arcsin; @@ -5,6 +17,18 @@ mod arcsinh; mod arctan; mod arctanh; +pub use cos::SubCommand as MathCos; +pub use cosh::SubCommand as MathCosH; +pub use sin::SubCommand as MathSin; +pub use sinh::SubCommand as MathSinH; +pub use tan::SubCommand as MathTan; +pub use tanh::SubCommand as MathTanH; + +pub use egamma::SubCommand as MathEulerGamma; +pub use phi::SubCommand as MathPhi; +pub use pi::SubCommand as MathPi; +pub use tau::SubCommand as MathTau; + pub use arccos::SubCommand as MathArcCos; pub use arccosh::SubCommand as MathArcCosH; pub use arcsin::SubCommand as MathArcSin; diff --git a/crates/nu-command/src/math/phi.rs b/crates/nu-cmd-extra/src/extra/math/phi.rs similarity index 100% rename from crates/nu-command/src/math/phi.rs rename to crates/nu-cmd-extra/src/extra/math/phi.rs diff --git a/crates/nu-command/src/math/pi.rs b/crates/nu-cmd-extra/src/extra/math/pi.rs similarity index 100% rename from crates/nu-command/src/math/pi.rs rename to crates/nu-cmd-extra/src/extra/math/pi.rs diff --git a/crates/nu-command/src/math/sin.rs b/crates/nu-cmd-extra/src/extra/math/sin.rs similarity index 100% rename from crates/nu-command/src/math/sin.rs rename to crates/nu-cmd-extra/src/extra/math/sin.rs diff --git a/crates/nu-command/src/math/sinh.rs b/crates/nu-cmd-extra/src/extra/math/sinh.rs similarity index 100% rename from crates/nu-command/src/math/sinh.rs rename to crates/nu-cmd-extra/src/extra/math/sinh.rs diff --git a/crates/nu-command/src/math/tan.rs b/crates/nu-cmd-extra/src/extra/math/tan.rs similarity index 100% rename from crates/nu-command/src/math/tan.rs rename to crates/nu-cmd-extra/src/extra/math/tan.rs diff --git a/crates/nu-command/src/math/tanh.rs b/crates/nu-cmd-extra/src/extra/math/tanh.rs similarity index 100% rename from crates/nu-command/src/math/tanh.rs rename to crates/nu-cmd-extra/src/extra/math/tanh.rs diff --git a/crates/nu-command/src/math/tau.rs b/crates/nu-cmd-extra/src/extra/math/tau.rs similarity index 100% rename from crates/nu-command/src/math/tau.rs rename to crates/nu-cmd-extra/src/extra/math/tau.rs diff --git a/crates/nu-cmd-extra/src/extra/mod.rs b/crates/nu-cmd-extra/src/extra/mod.rs index 8f77bf7dd..e3c6dbaef 100644 --- a/crates/nu-cmd-extra/src/extra/mod.rs +++ b/crates/nu-cmd-extra/src/extra/mod.rs @@ -31,6 +31,18 @@ pub use bits::BitsShl; pub use bits::BitsShr; pub use bits::BitsXor; +pub use math::MathCos; +pub use math::MathCosH; +pub use math::MathSin; +pub use math::MathSinH; +pub use math::MathTan; +pub use math::MathTanH; + +pub use math::MathEulerGamma; +pub use math::MathPhi; +pub use math::MathPi; +pub use math::MathTau; + pub use math::MathArcCos; pub use math::MathArcCosH; pub use math::MathArcSin; @@ -113,7 +125,15 @@ pub fn add_extra_command_context(mut engine_state: EngineState) -> EngineState { MathArcTan, MathArcSinH, MathArcCosH, - MathArcTanH + MathArcTanH, + MathSin, + MathCos, + MathTan, + MathSinH, + MathCosH, + MathTanH, + MathPi, + MathTau }; working_set.render() diff --git a/crates/nu-command/src/default_context.rs b/crates/nu-command/src/default_context.rs index 86477dad2..23c3538bb 100644 --- a/crates/nu-command/src/default_context.rs +++ b/crates/nu-command/src/default_context.rs @@ -327,14 +327,6 @@ pub fn add_shell_command_context(mut engine_state: EngineState) -> EngineState { MathStddev, MathSum, MathVariance, - MathSin, - MathCos, - MathTan, - MathSinH, - MathCosH, - MathTanH, - MathPi, - MathTau, MathEuler, MathExp, MathLn, diff --git a/crates/nu-command/src/example_test.rs b/crates/nu-command/src/example_test.rs index fb6b122c7..dc74d62a3 100644 --- a/crates/nu-command/src/example_test.rs +++ b/crates/nu-command/src/example_test.rs @@ -9,9 +9,9 @@ pub fn test_examples(cmd: impl Command + 'static) { #[cfg(test)] mod test_examples { use super::super::{ - Ansi, Date, Enumerate, Flatten, From, Get, Into, IntoString, Math, MathEuler, MathPi, - MathRound, ParEach, Path, PathParse, Random, Sort, SortBy, Split, SplitColumn, SplitRow, - Str, StrJoin, StrLength, StrReplace, Update, Url, Values, Wrap, + Ansi, Date, Enumerate, Flatten, From, Get, Into, IntoString, Math, MathEuler, MathRound, + ParEach, Path, PathParse, Random, Sort, SortBy, Split, SplitColumn, SplitRow, Str, StrJoin, + StrLength, StrReplace, Update, Url, Values, Wrap, }; use crate::{Each, To}; use nu_cmd_lang::example_support::{ @@ -80,7 +80,6 @@ mod test_examples { working_set.add_decl(Box::new(Let)); working_set.add_decl(Box::new(Math)); working_set.add_decl(Box::new(MathEuler)); - working_set.add_decl(Box::new(MathPi)); working_set.add_decl(Box::new(MathRound)); working_set.add_decl(Box::new(Mut)); working_set.add_decl(Box::new(Path)); diff --git a/crates/nu-command/src/math/mod.rs b/crates/nu-command/src/math/mod.rs index 520ee6d82..80d102cf4 100644 --- a/crates/nu-command/src/math/mod.rs +++ b/crates/nu-command/src/math/mod.rs @@ -1,9 +1,6 @@ mod abs; mod avg; mod ceil; -mod cos; -mod cosh; -mod egamma; mod euler; mod exp; mod floor; @@ -14,19 +11,12 @@ mod max; mod median; mod min; mod mode; -mod phi; -mod pi; mod product; mod reducers; mod round; -mod sin; -mod sinh; mod sqrt; mod stddev; mod sum; -mod tan; -mod tanh; -mod tau; mod utils; mod variance; @@ -46,18 +36,7 @@ pub use stddev::SubCommand as MathStddev; pub use sum::SubCommand as MathSum; pub use variance::SubCommand as MathVariance; -pub use cos::SubCommand as MathCos; -pub use cosh::SubCommand as MathCosH; -pub use sin::SubCommand as MathSin; -pub use sinh::SubCommand as MathSinH; -pub use tan::SubCommand as MathTan; -pub use tanh::SubCommand as MathTanH; - -pub use egamma::SubCommand as MathEulerGamma; pub use euler::SubCommand as MathEuler; -pub use phi::SubCommand as MathPhi; -pub use pi::SubCommand as MathPi; -pub use tau::SubCommand as MathTau; pub use self::log::SubCommand as MathLog; pub use exp::SubCommand as MathExp;