forked from extern/nushell
36 lines
839 B
Rust
36 lines
839 B
Rust
|
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("wrap").required(
|
||
|
"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)
|
||
|
}
|
||
|
}
|