forked from extern/nushell
preparing for into subcommands (#3299)
This commit is contained in:
parent
93f3ed98e1
commit
a853880e07
@ -70,7 +70,7 @@ pub(crate) mod histogram;
|
|||||||
pub(crate) mod history;
|
pub(crate) mod history;
|
||||||
pub(crate) mod if_;
|
pub(crate) mod if_;
|
||||||
pub(crate) mod insert;
|
pub(crate) mod insert;
|
||||||
pub(crate) mod into_int;
|
pub(crate) mod into;
|
||||||
pub(crate) mod keep;
|
pub(crate) mod keep;
|
||||||
pub(crate) mod last;
|
pub(crate) mod last;
|
||||||
pub(crate) mod length;
|
pub(crate) mod length;
|
||||||
@ -171,6 +171,8 @@ pub(crate) use each::EachWindow;
|
|||||||
pub(crate) use echo::Echo;
|
pub(crate) use echo::Echo;
|
||||||
pub(crate) use empty::Command as Empty;
|
pub(crate) use empty::Command as Empty;
|
||||||
pub(crate) use if_::If;
|
pub(crate) use if_::If;
|
||||||
|
pub(crate) use into::Into;
|
||||||
|
pub(crate) use into::IntoInt;
|
||||||
pub(crate) use nu::NuPlugin;
|
pub(crate) use nu::NuPlugin;
|
||||||
pub(crate) use update::Command as Update;
|
pub(crate) use update::Command as Update;
|
||||||
pub(crate) mod kill;
|
pub(crate) mod kill;
|
||||||
@ -212,7 +214,6 @@ pub(crate) use help::Help;
|
|||||||
pub(crate) use histogram::Histogram;
|
pub(crate) use histogram::Histogram;
|
||||||
pub(crate) use history::History;
|
pub(crate) use history::History;
|
||||||
pub(crate) use insert::Command as Insert;
|
pub(crate) use insert::Command as Insert;
|
||||||
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 length::Length;
|
||||||
|
@ -121,6 +121,7 @@ pub fn create_default_context(interactive: bool) -> Result<EvaluationContext, Bo
|
|||||||
whole_stream_command(Get),
|
whole_stream_command(Get),
|
||||||
whole_stream_command(Update),
|
whole_stream_command(Update),
|
||||||
whole_stream_command(Insert),
|
whole_stream_command(Insert),
|
||||||
|
whole_stream_command(Into),
|
||||||
whole_stream_command(IntoInt),
|
whole_stream_command(IntoInt),
|
||||||
whole_stream_command(SplitBy),
|
whole_stream_command(SplitBy),
|
||||||
// Row manipulation
|
// Row manipulation
|
||||||
|
39
crates/nu-command/src/commands/into/command.rs
Normal file
39
crates/nu-command/src/commands/into/command.rs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
use crate::prelude::*;
|
||||||
|
use nu_engine::WholeStreamCommand;
|
||||||
|
use nu_errors::ShellError;
|
||||||
|
use nu_protocol::{ReturnSuccess, Signature, UntaggedValue};
|
||||||
|
|
||||||
|
pub struct Command;
|
||||||
|
|
||||||
|
impl WholeStreamCommand for Command {
|
||||||
|
fn name(&self) -> &str {
|
||||||
|
"into"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn signature(&self) -> Signature {
|
||||||
|
Signature::build("into")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn usage(&self) -> &str {
|
||||||
|
"Apply into function."
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
|
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 {})
|
||||||
|
}
|
||||||
|
}
|
@ -4,17 +4,16 @@ use nu_errors::ShellError;
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ColumnPath, Primitive, ReturnSuccess, Signature, SyntaxShape, UntaggedValue, Value,
|
ColumnPath, Primitive, ReturnSuccess, Signature, SyntaxShape, UntaggedValue, Value,
|
||||||
};
|
};
|
||||||
|
|
||||||
use num_bigint::{BigInt, ToBigInt};
|
use num_bigint::{BigInt, ToBigInt};
|
||||||
|
|
||||||
pub struct IntoInt;
|
pub struct SubCommand;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct IntoIntArgs {
|
pub struct Arguments {
|
||||||
pub rest: Vec<ColumnPath>,
|
pub rest: Vec<ColumnPath>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WholeStreamCommand for IntoInt {
|
impl WholeStreamCommand for SubCommand {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
"into int"
|
"into int"
|
||||||
}
|
}
|
||||||
@ -87,7 +86,7 @@ impl WholeStreamCommand for IntoInt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn into_int(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn into_int(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let (IntoIntArgs { rest: column_paths }, input) = args.process()?;
|
let (Arguments { rest: column_paths }, input) = args.process()?;
|
||||||
|
|
||||||
Ok(input
|
Ok(input
|
||||||
.map(move |v| {
|
.map(move |v| {
|
||||||
@ -174,13 +173,13 @@ fn int_from_string(a_string: &str, tag: &Tag) -> Result<BigInt, ShellError> {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::IntoInt;
|
|
||||||
use super::ShellError;
|
use super::ShellError;
|
||||||
|
use super::SubCommand;
|
||||||
|
|
||||||
#[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(IntoInt {})
|
test_examples(SubCommand {})
|
||||||
}
|
}
|
||||||
}
|
}
|
5
crates/nu-command/src/commands/into/mod.rs
Normal file
5
crates/nu-command/src/commands/into/mod.rs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
mod command;
|
||||||
|
mod int;
|
||||||
|
|
||||||
|
pub use command::Command as Into;
|
||||||
|
pub use int::SubCommand as IntoInt;
|
Loading…
Reference in New Issue
Block a user