nushell/crates/nu-command/src/filters/get.rs

36 lines
838 B
Rust
Raw Normal View History

2021-10-02 04:59:11 +02:00
use nu_engine::CallExt;
use nu_protocol::ast::{Call, CellPath};
use nu_protocol::engine::{Command, EvaluationContext};
use nu_protocol::{Signature, SyntaxShape, Value};
pub struct Get;
impl Command for Get {
fn name(&self) -> &str {
"get"
}
fn usage(&self) -> &str {
"Extract data using a cell path."
}
fn signature(&self) -> nu_protocol::Signature {
Signature::build("get").required(
2021-10-02 04:59:11 +02:00
"cell_path",
SyntaxShape::CellPath,
"the cell path to the data",
)
}
fn run(
&self,
context: &EvaluationContext,
call: &Call,
input: Value,
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
let cell_path: CellPath = call.req(context, 0)?;
input.follow_cell_path(&cell_path.members)
}
}