From a0cecf76589aed88ba412ec51e70d0c3fc210dd2 Mon Sep 17 00:00:00 2001 From: Stefan Holderbach Date: Thu, 10 Aug 2023 20:01:47 +0200 Subject: [PATCH] Move `format duration`/`filesize` back into core (#9978) # Description Those two commands are very complementary to `into duration` and `into filesize` when you want to coerce a particular string output. This keeps the old `format` command with its separate formatting syntax still in `nu-cmd-extra`. # User-Facing Changes `format filesize` is back accessible with the default build. The new `format duration` command is also available to everybody # Tests + Formatting --- crates/nu-cmd-extra/src/extra/mod.rs | 2 -- crates/nu-cmd-extra/src/extra/strings/format/mod.rs | 4 ---- crates/nu-command/src/default_context.rs | 4 +++- .../src/extra => nu-command/src}/strings/format/duration.rs | 0 .../src/extra => nu-command/src}/strings/format/filesize.rs | 6 +++--- crates/nu-command/src/strings/format/mod.rs | 4 ++++ crates/nu-command/src/strings/mod.rs | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) rename crates/{nu-cmd-extra/src/extra => nu-command/src}/strings/format/duration.rs (100%) rename crates/{nu-cmd-extra/src/extra => nu-command/src}/strings/format/filesize.rs (97%) diff --git a/crates/nu-cmd-extra/src/extra/mod.rs b/crates/nu-cmd-extra/src/extra/mod.rs index a4a855a101..2f65f92924 100644 --- a/crates/nu-cmd-extra/src/extra/mod.rs +++ b/crates/nu-cmd-extra/src/extra/mod.rs @@ -85,8 +85,6 @@ pub fn add_extra_command_context(mut engine_state: EngineState) -> EngineState { bind_command!( strings::format::Format, - strings::format::FileSize, - strings::format::FormatDuration, strings::encode_decode::EncodeHex, strings::encode_decode::DecodeHex, strings::str_::case::Str, diff --git a/crates/nu-cmd-extra/src/extra/strings/format/mod.rs b/crates/nu-cmd-extra/src/extra/strings/format/mod.rs index 582ad120cd..98fd4aea34 100644 --- a/crates/nu-cmd-extra/src/extra/strings/format/mod.rs +++ b/crates/nu-cmd-extra/src/extra/strings/format/mod.rs @@ -1,7 +1,3 @@ mod command; -mod duration; -mod filesize; pub(crate) use command::Format; -pub(crate) use duration::FormatDuration; -pub(crate) use filesize::FileSize; diff --git a/crates/nu-command/src/default_context.rs b/crates/nu-command/src/default_context.rs index 54a4041051..fa364645d4 100644 --- a/crates/nu-command/src/default_context.rs +++ b/crates/nu-command/src/default_context.rs @@ -192,7 +192,9 @@ pub fn add_shell_command_context(mut engine_state: EngineState) -> EngineState { StrSubstring, StrTrim, StrUpcase, - FormatDate + FormatDate, + FormatDuration, + FormatFilesize, }; // FileSystem diff --git a/crates/nu-cmd-extra/src/extra/strings/format/duration.rs b/crates/nu-command/src/strings/format/duration.rs similarity index 100% rename from crates/nu-cmd-extra/src/extra/strings/format/duration.rs rename to crates/nu-command/src/strings/format/duration.rs diff --git a/crates/nu-cmd-extra/src/extra/strings/format/filesize.rs b/crates/nu-command/src/strings/format/filesize.rs similarity index 97% rename from crates/nu-cmd-extra/src/extra/strings/format/filesize.rs rename to crates/nu-command/src/strings/format/filesize.rs index c51e412644..0ad430c7a3 100644 --- a/crates/nu-cmd-extra/src/extra/strings/format/filesize.rs +++ b/crates/nu-command/src/strings/format/filesize.rs @@ -19,9 +19,9 @@ impl CmdArgument for Arguments { } #[derive(Clone)] -pub struct FileSize; +pub struct FormatFilesize; -impl Command for FileSize { +impl Command for FormatFilesize { fn name(&self) -> &str { "format filesize" } @@ -129,6 +129,6 @@ mod tests { fn test_examples() { use crate::test_examples; - test_examples(FileSize) + test_examples(FormatFilesize) } } diff --git a/crates/nu-command/src/strings/format/mod.rs b/crates/nu-command/src/strings/format/mod.rs index 635a9568f3..6802b20859 100644 --- a/crates/nu-command/src/strings/format/mod.rs +++ b/crates/nu-command/src/strings/format/mod.rs @@ -1,3 +1,7 @@ mod date; +mod duration; +mod filesize; +pub use self::filesize::FormatFilesize; pub use date::FormatDate; +pub use duration::FormatDuration; diff --git a/crates/nu-command/src/strings/mod.rs b/crates/nu-command/src/strings/mod.rs index 5f1694a024..2d47afc576 100644 --- a/crates/nu-command/src/strings/mod.rs +++ b/crates/nu-command/src/strings/mod.rs @@ -10,7 +10,7 @@ mod str_; pub use char_::Char; pub use detect_columns::*; pub use encode_decode::*; -pub use format::FormatDate; +pub use format::*; pub use parse::*; pub use size::Size; pub use split::*;