2021-10-02 04:59:11 +02:00
|
|
|
use nu_engine::CallExt;
|
|
|
|
use nu_protocol::ast::{Call, CellPath};
|
2021-10-25 18:58:58 +02:00
|
|
|
use nu_protocol::engine::{Command, EngineState, Stack};
|
|
|
|
use nu_protocol::{IntoPipelineData, PipelineData, Signature, SyntaxShape};
|
2021-10-02 04:59:11 +02:00
|
|
|
|
2021-10-25 06:01:02 +02:00
|
|
|
#[derive(Clone)]
|
2021-10-02 04:59:11 +02:00
|
|
|
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 {
|
2021-10-05 21:59:17 +02:00
|
|
|
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,
|
2021-10-25 08:31:39 +02:00
|
|
|
engine_state: &EngineState,
|
|
|
|
stack: &mut Stack,
|
2021-10-02 04:59:11 +02:00
|
|
|
call: &Call,
|
2021-10-25 06:01:02 +02:00
|
|
|
input: PipelineData,
|
|
|
|
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
2021-10-25 08:31:39 +02:00
|
|
|
let cell_path: CellPath = call.req(engine_state, stack, 0)?;
|
2021-10-02 04:59:11 +02:00
|
|
|
|
2021-10-25 06:24:10 +02:00
|
|
|
input
|
|
|
|
.follow_cell_path(&cell_path.members)
|
|
|
|
.map(|x| x.into_pipeline_data())
|
2021-10-02 04:59:11 +02:00
|
|
|
}
|
|
|
|
}
|