From a853880e07b465ee2b9b3f6d8867cffd27e86142 Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Sat, 10 Apr 2021 11:29:11 -0500 Subject: [PATCH] preparing for into subcommands (#3299) --- crates/nu-command/src/commands.rs | 5 ++- .../src/commands/default_context.rs | 1 + .../nu-command/src/commands/into/command.rs | 39 +++++++++++++++++++ .../src/commands/{into_int.rs => into/int.rs} | 13 +++---- crates/nu-command/src/commands/into/mod.rs | 5 +++ 5 files changed, 54 insertions(+), 9 deletions(-) create mode 100644 crates/nu-command/src/commands/into/command.rs rename crates/nu-command/src/commands/{into_int.rs => into/int.rs} (96%) create mode 100644 crates/nu-command/src/commands/into/mod.rs diff --git a/crates/nu-command/src/commands.rs b/crates/nu-command/src/commands.rs index adf67855..a1f0cd03 100644 --- a/crates/nu-command/src/commands.rs +++ b/crates/nu-command/src/commands.rs @@ -70,7 +70,7 @@ pub(crate) mod histogram; pub(crate) mod history; pub(crate) mod if_; pub(crate) mod insert; -pub(crate) mod into_int; +pub(crate) mod into; pub(crate) mod keep; pub(crate) mod last; pub(crate) mod length; @@ -171,6 +171,8 @@ pub(crate) use each::EachWindow; pub(crate) use echo::Echo; pub(crate) use empty::Command as Empty; pub(crate) use if_::If; +pub(crate) use into::Into; +pub(crate) use into::IntoInt; pub(crate) use nu::NuPlugin; pub(crate) use update::Command as Update; pub(crate) mod kill; @@ -212,7 +214,6 @@ pub(crate) use help::Help; pub(crate) use histogram::Histogram; pub(crate) use history::History; pub(crate) use insert::Command as Insert; -pub(crate) use into_int::IntoInt; pub(crate) use keep::{Keep, KeepUntil, KeepWhile}; pub(crate) use last::Last; pub(crate) use length::Length; diff --git a/crates/nu-command/src/commands/default_context.rs b/crates/nu-command/src/commands/default_context.rs index e564bf3d..bcaf5f36 100644 --- a/crates/nu-command/src/commands/default_context.rs +++ b/crates/nu-command/src/commands/default_context.rs @@ -121,6 +121,7 @@ pub fn create_default_context(interactive: bool) -> Result &str { + "into" + } + + fn signature(&self) -> Signature { + Signature::build("into") + } + + fn usage(&self) -> &str { + "Apply into function." + } + + fn run(&self, args: CommandArgs) -> Result { + Ok(OutputStream::one(ReturnSuccess::value( + UntaggedValue::string(get_full_help(&Command, &args.scope)).into_value(Tag::unknown()), + ))) + } +} + +#[cfg(test)] +mod tests { + use super::Command; + use super::ShellError; + + #[test] + fn examples_work_as_expected() -> Result<(), ShellError> { + use crate::examples::test as test_examples; + + test_examples(Command {}) + } +} diff --git a/crates/nu-command/src/commands/into_int.rs b/crates/nu-command/src/commands/into/int.rs similarity index 96% rename from crates/nu-command/src/commands/into_int.rs rename to crates/nu-command/src/commands/into/int.rs index c0814051..255189a1 100644 --- a/crates/nu-command/src/commands/into_int.rs +++ b/crates/nu-command/src/commands/into/int.rs @@ -4,17 +4,16 @@ use nu_errors::ShellError; use nu_protocol::{ ColumnPath, Primitive, ReturnSuccess, Signature, SyntaxShape, UntaggedValue, Value, }; - use num_bigint::{BigInt, ToBigInt}; -pub struct IntoInt; +pub struct SubCommand; #[derive(Deserialize)] -pub struct IntoIntArgs { +pub struct Arguments { pub rest: Vec, } -impl WholeStreamCommand for IntoInt { +impl WholeStreamCommand for SubCommand { fn name(&self) -> &str { "into int" } @@ -87,7 +86,7 @@ impl WholeStreamCommand for IntoInt { } fn into_int(args: CommandArgs) -> Result { - let (IntoIntArgs { rest: column_paths }, input) = args.process()?; + let (Arguments { rest: column_paths }, input) = args.process()?; Ok(input .map(move |v| { @@ -174,13 +173,13 @@ fn int_from_string(a_string: &str, tag: &Tag) -> Result { #[cfg(test)] mod tests { - use super::IntoInt; use super::ShellError; + use super::SubCommand; #[test] fn examples_work_as_expected() -> Result<(), ShellError> { use crate::examples::test as test_examples; - test_examples(IntoInt {}) + test_examples(SubCommand {}) } } diff --git a/crates/nu-command/src/commands/into/mod.rs b/crates/nu-command/src/commands/into/mod.rs new file mode 100644 index 00000000..9e53deb2 --- /dev/null +++ b/crates/nu-command/src/commands/into/mod.rs @@ -0,0 +1,5 @@ +mod command; +mod int; + +pub use command::Command as Into; +pub use int::SubCommand as IntoInt;