nushell/src/commands/enter.rs

47 lines
1.3 KiB
Rust
Raw Normal View History

2019-08-07 19:49:11 +02:00
use crate::commands::command::CommandAction;
2019-08-14 19:02:39 +02:00
use crate::commands::{PerItemCommand, RawCommandArgs};
2019-08-07 19:49:11 +02:00
use crate::errors::ShellError;
2019-08-14 19:02:39 +02:00
use crate::evaluate::Scope;
use crate::parser::registry;
2019-08-07 19:49:11 +02:00
use crate::prelude::*;
2019-08-14 19:02:39 +02:00
pub struct Enter;
2019-08-09 06:51:21 +02:00
2019-08-14 19:02:39 +02:00
impl PerItemCommand for Enter {
fn name(&self) -> &str {
"enter"
2019-08-07 19:49:11 +02:00
}
2019-08-14 19:02:39 +02:00
fn signature(&self) -> registry::Signature {
Signature::build("enter").required("location", SyntaxType::Block)
}
fn run(
&self,
args: RawCommandArgs,
registry: &registry::CommandRegistry,
input: Tagged<Value>,
) -> Result<VecDeque<ReturnValue>, ShellError> {
let call_info = args
.call_info
.evaluate(registry, &Scope::it_value(input))
.unwrap();
2019-08-07 19:49:11 +02:00
2019-08-14 19:02:39 +02:00
match call_info.args.expect_nth(0)? {
Tagged {
item: Value::Primitive(Primitive::String(location)),
..
} => Ok(vec![Ok(ReturnSuccess::Action(CommandAction::EnterShell(
location.to_string(),
)))]
.into()),
x => Ok(
vec![Ok(ReturnSuccess::Action(CommandAction::EnterValueShell(
x.clone(),
)))]
.into(),
),
}
}
2019-08-07 19:49:11 +02:00
}