2019-08-09 04:51:21 +00:00
|
|
|
use crate::commands::command::{CommandAction, StaticCommand};
|
2019-06-13 21:47:25 +00:00
|
|
|
use crate::errors::ShellError;
|
2019-08-09 04:51:21 +00:00
|
|
|
use crate::parser::registry::{CommandRegistry, Signature};
|
2019-06-13 21:47:25 +00:00
|
|
|
use crate::prelude::*;
|
|
|
|
|
2019-08-07 17:49:11 +00:00
|
|
|
pub struct Exit;
|
|
|
|
|
2019-08-09 04:51:21 +00:00
|
|
|
impl StaticCommand for Exit {
|
|
|
|
fn run(
|
|
|
|
&self,
|
|
|
|
args: CommandArgs,
|
|
|
|
registry: &CommandRegistry,
|
|
|
|
) -> Result<OutputStream, ShellError> {
|
|
|
|
exit(args, registry)
|
2019-08-07 17:49:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn name(&self) -> &str {
|
|
|
|
"exit"
|
|
|
|
}
|
|
|
|
|
2019-08-09 04:51:21 +00:00
|
|
|
fn signature(&self) -> Signature {
|
|
|
|
Signature::build("exit").switch("now")
|
2019-08-07 17:49:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-09 04:51:21 +00:00
|
|
|
pub fn exit(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
|
|
|
|
let args = args.evaluate_once(registry)?;
|
|
|
|
|
2019-08-07 17:49:11 +00: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 21:47:25 +00:00
|
|
|
}
|