mirror of
https://github.com/nushell/nushell
synced 2024-12-28 22:13:10 +00:00
Add better exit command (#369)
This commit is contained in:
parent
f052b3313d
commit
5d88ed6c75
6 changed files with 44 additions and 12 deletions
|
@ -1,7 +1,4 @@
|
||||||
use nu_protocol::{
|
use nu_protocol::engine::{EngineState, StateWorkingSet};
|
||||||
engine::{EngineState, StateWorkingSet},
|
|
||||||
Signature,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
|
@ -43,6 +40,7 @@ pub fn create_default_context() -> EngineState {
|
||||||
Drop,
|
Drop,
|
||||||
Each,
|
Each,
|
||||||
Echo,
|
Echo,
|
||||||
|
Exit,
|
||||||
ExportCommand,
|
ExportCommand,
|
||||||
ExportDef,
|
ExportDef,
|
||||||
ExportEnv,
|
ExportEnv,
|
||||||
|
@ -108,6 +106,7 @@ pub fn create_default_context() -> EngineState {
|
||||||
Select,
|
Select,
|
||||||
Shuffle,
|
Shuffle,
|
||||||
Size,
|
Size,
|
||||||
|
Source,
|
||||||
Split,
|
Split,
|
||||||
SplitChars,
|
SplitChars,
|
||||||
SplitColumn,
|
SplitColumn,
|
||||||
|
@ -150,10 +149,7 @@ pub fn create_default_context() -> EngineState {
|
||||||
bind_command!(OpenDataFrame, ToDataFrame);
|
bind_command!(OpenDataFrame, ToDataFrame);
|
||||||
|
|
||||||
// This is a WIP proof of concept
|
// This is a WIP proof of concept
|
||||||
bind_command!(ListGitBranches, Git, GitCheckout, Source);
|
// bind_command!(ListGitBranches, Git, GitCheckout, Source);
|
||||||
|
|
||||||
let sig = Signature::build("exit");
|
|
||||||
working_set.add_decl(sig.predeclare());
|
|
||||||
|
|
||||||
working_set.render()
|
working_set.render()
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,6 +9,7 @@ mod filesystem;
|
||||||
mod filters;
|
mod filters;
|
||||||
mod formats;
|
mod formats;
|
||||||
mod math;
|
mod math;
|
||||||
|
mod shells;
|
||||||
mod strings;
|
mod strings;
|
||||||
mod system;
|
mod system;
|
||||||
mod viewers;
|
mod viewers;
|
||||||
|
@ -27,6 +28,7 @@ pub use filesystem::*;
|
||||||
pub use filters::*;
|
pub use filters::*;
|
||||||
pub use formats::*;
|
pub use formats::*;
|
||||||
pub use math::*;
|
pub use math::*;
|
||||||
|
pub use shells::*;
|
||||||
pub use strings::*;
|
pub use strings::*;
|
||||||
pub use system::*;
|
pub use system::*;
|
||||||
pub use viewers::*;
|
pub use viewers::*;
|
||||||
|
|
33
crates/nu-command/src/shells/exit.rs
Normal file
33
crates/nu-command/src/shells/exit.rs
Normal file
|
@ -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<PipelineData, ShellError> {
|
||||||
|
//TODO: add more shell support
|
||||||
|
|
||||||
|
std::process::exit(0);
|
||||||
|
}
|
||||||
|
}
|
3
crates/nu-command/src/shells/mod.rs
Normal file
3
crates/nu-command/src/shells/mod.rs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
mod exit;
|
||||||
|
|
||||||
|
pub use exit::Exit;
|
|
@ -42,6 +42,7 @@ pub enum Category {
|
||||||
Filters,
|
Filters,
|
||||||
Formats,
|
Formats,
|
||||||
Math,
|
Math,
|
||||||
|
Shells,
|
||||||
Strings,
|
Strings,
|
||||||
System,
|
System,
|
||||||
Viewers,
|
Viewers,
|
||||||
|
@ -61,6 +62,7 @@ impl std::fmt::Display for Category {
|
||||||
Category::Filters => "filters",
|
Category::Filters => "filters",
|
||||||
Category::Formats => "formats",
|
Category::Formats => "formats",
|
||||||
Category::Math => "math",
|
Category::Math => "math",
|
||||||
|
Category::Shells => "shells",
|
||||||
Category::Strings => "strings",
|
Category::Strings => "strings",
|
||||||
Category::System => "system",
|
Category::System => "system",
|
||||||
Category::Viewers => "viewers",
|
Category::Viewers => "viewers",
|
||||||
|
|
|
@ -269,10 +269,6 @@ fn main() -> Result<()> {
|
||||||
let input = line_editor.read_line(prompt);
|
let input = line_editor.read_line(prompt);
|
||||||
match input {
|
match input {
|
||||||
Ok(Signal::Success(s)) => {
|
Ok(Signal::Success(s)) => {
|
||||||
if s.trim() == "exit" {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
eval_source(
|
eval_source(
|
||||||
&mut engine_state,
|
&mut engine_state,
|
||||||
&mut stack,
|
&mut stack,
|
||||||
|
|
Loading…
Reference in a new issue