nushell/src/commands/exit.rs

35 lines
895 B
Rust
Raw Normal View History

2019-08-09 06:51:21 +02:00
use crate::commands::command::{CommandAction, StaticCommand};
2019-06-13 23:47:25 +02:00
use crate::errors::ShellError;
2019-08-09 06:51:21 +02:00
use crate::parser::registry::{CommandRegistry, Signature};
2019-06-13 23:47:25 +02:00
use crate::prelude::*;
2019-08-07 19:49:11 +02:00
pub struct Exit;
2019-08-09 06:51:21 +02:00
impl StaticCommand for Exit {
fn run(
&self,
args: CommandArgs,
registry: &CommandRegistry,
) -> Result<OutputStream, ShellError> {
exit(args, registry)
2019-08-07 19:49:11 +02:00
}
fn name(&self) -> &str {
"exit"
}
2019-08-09 06:51:21 +02:00
fn signature(&self) -> Signature {
Signature::build("exit").switch("now")
2019-08-07 19:49:11 +02:00
}
}
2019-08-09 06:51:21 +02:00
pub fn exit(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
let args = args.evaluate_once(registry)?;
2019-08-07 19:49:11 +02:00
if args.call_info.args.has("now") {
Ok(vec![Ok(ReturnSuccess::Action(CommandAction::Exit))].into())
} else {
Ok(vec![Ok(ReturnSuccess::Action(CommandAction::LeaveShell))].into())
}
2019-06-13 23:47:25 +02:00
}