nushell/src/commands/exit.rs

40 lines
1.0 KiB
Rust
Raw Normal View History

use crate::commands::command::WholeStreamCommand;
use crate::context::CommandRegistry;
2019-06-13 23:47:25 +02:00
use crate::prelude::*;
use nu_errors::ShellError;
use nu_protocol::{CommandAction, ReturnSuccess, Signature};
2019-06-13 23:47:25 +02:00
2019-08-07 19:49:11 +02:00
pub struct Exit;
2019-08-15 07:02:02 +02:00
impl WholeStreamCommand for Exit {
fn name(&self) -> &str {
"exit"
}
fn signature(&self) -> Signature {
2019-10-28 06:15:35 +01:00
Signature::build("exit").switch("now", "exit out of the shell immediately")
}
fn usage(&self) -> &str {
"Exit the current shell (or all shells)"
}
2019-08-09 06:51:21 +02:00
fn run(
&self,
args: CommandArgs,
registry: &CommandRegistry,
) -> Result<OutputStream, ShellError> {
exit(args, registry)
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
}