diff --git a/crates/nu-command/src/default_context.rs b/crates/nu-command/src/default_context.rs index b634339684..55d3d34def 100644 --- a/crates/nu-command/src/default_context.rs +++ b/crates/nu-command/src/default_context.rs @@ -1,7 +1,4 @@ -use nu_protocol::{ - engine::{EngineState, StateWorkingSet}, - Signature, -}; +use nu_protocol::engine::{EngineState, StateWorkingSet}; use crate::*; @@ -43,6 +40,7 @@ pub fn create_default_context() -> EngineState { Drop, Each, Echo, + Exit, ExportCommand, ExportDef, ExportEnv, @@ -108,6 +106,7 @@ pub fn create_default_context() -> EngineState { Select, Shuffle, Size, + Source, Split, SplitChars, SplitColumn, @@ -150,10 +149,7 @@ pub fn create_default_context() -> EngineState { bind_command!(OpenDataFrame, ToDataFrame); // This is a WIP proof of concept - bind_command!(ListGitBranches, Git, GitCheckout, Source); - - let sig = Signature::build("exit"); - working_set.add_decl(sig.predeclare()); + // bind_command!(ListGitBranches, Git, GitCheckout, Source); working_set.render() }; diff --git a/crates/nu-command/src/lib.rs b/crates/nu-command/src/lib.rs index bb7e60d9d3..ef23b8beaa 100644 --- a/crates/nu-command/src/lib.rs +++ b/crates/nu-command/src/lib.rs @@ -9,6 +9,7 @@ mod filesystem; mod filters; mod formats; mod math; +mod shells; mod strings; mod system; mod viewers; @@ -27,6 +28,7 @@ pub use filesystem::*; pub use filters::*; pub use formats::*; pub use math::*; +pub use shells::*; pub use strings::*; pub use system::*; pub use viewers::*; diff --git a/crates/nu-command/src/shells/exit.rs b/crates/nu-command/src/shells/exit.rs new file mode 100644 index 0000000000..092c6ef08b --- /dev/null +++ b/crates/nu-command/src/shells/exit.rs @@ -0,0 +1,33 @@ +use nu_protocol::ast::Call; +use nu_protocol::engine::{Command, EngineState, Stack}; +use nu_protocol::{Category, PipelineData, ShellError, Signature}; + +/// Source a file for environment variables. +#[derive(Clone)] +pub struct Exit; + +impl Command for Exit { + fn name(&self) -> &str { + "exit" + } + + fn signature(&self) -> Signature { + Signature::build("exit").category(Category::Shells) + } + + fn usage(&self) -> &str { + "Runs a script file in the current context." + } + + fn run( + &self, + _engine_state: &EngineState, + _stack: &mut Stack, + _call: &Call, + _input: PipelineData, + ) -> Result { + //TODO: add more shell support + + std::process::exit(0); + } +} diff --git a/crates/nu-command/src/shells/mod.rs b/crates/nu-command/src/shells/mod.rs new file mode 100644 index 0000000000..11d875e645 --- /dev/null +++ b/crates/nu-command/src/shells/mod.rs @@ -0,0 +1,3 @@ +mod exit; + +pub use exit::Exit; diff --git a/crates/nu-protocol/src/signature.rs b/crates/nu-protocol/src/signature.rs index 81d8152a1e..e7fa3a4975 100644 --- a/crates/nu-protocol/src/signature.rs +++ b/crates/nu-protocol/src/signature.rs @@ -42,6 +42,7 @@ pub enum Category { Filters, Formats, Math, + Shells, Strings, System, Viewers, @@ -61,6 +62,7 @@ impl std::fmt::Display for Category { Category::Filters => "filters", Category::Formats => "formats", Category::Math => "math", + Category::Shells => "shells", Category::Strings => "strings", Category::System => "system", Category::Viewers => "viewers", diff --git a/src/main.rs b/src/main.rs index ce096c1d4d..0cfe93c6b7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -269,10 +269,6 @@ fn main() -> Result<()> { let input = line_editor.read_line(prompt); match input { Ok(Signal::Success(s)) => { - if s.trim() == "exit" { - break; - } - eval_source( &mut engine_state, &mut stack,