2022-10-21 17:08:57 +00:00
|
|
|
use nu_engine::get_full_help;
|
2021-10-29 06:26:29 +00:00
|
|
|
use nu_protocol::ast::Call;
|
|
|
|
use nu_protocol::engine::{Command, EngineState, Stack};
|
2022-12-21 19:20:46 +00:00
|
|
|
use nu_protocol::{Category, IntoPipelineData, PipelineData, ShellError, Signature, Type, Value};
|
2021-10-29 06:26:29 +00:00
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct To;
|
|
|
|
|
|
|
|
impl Command for To {
|
|
|
|
fn name(&self) -> &str {
|
|
|
|
"to"
|
|
|
|
}
|
|
|
|
|
|
|
|
fn usage(&self) -> &str {
|
|
|
|
"Translate structured data to a format"
|
|
|
|
}
|
|
|
|
|
|
|
|
fn signature(&self) -> nu_protocol::Signature {
|
2022-12-21 19:20:46 +00:00
|
|
|
Signature::build("to")
|
|
|
|
.category(Category::Formats)
|
|
|
|
.input_output_types(vec![(Type::Nothing, Type::String)])
|
2021-10-29 06:26:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn run(
|
|
|
|
&self,
|
2022-10-21 17:08:57 +00:00
|
|
|
engine_state: &EngineState,
|
|
|
|
stack: &mut Stack,
|
2021-11-06 05:50:33 +00:00
|
|
|
call: &Call,
|
2021-10-29 06:26:29 +00:00
|
|
|
_input: PipelineData,
|
|
|
|
) -> Result<nu_protocol::PipelineData, ShellError> {
|
2022-10-21 17:08:57 +00:00
|
|
|
Ok(Value::String {
|
2022-11-20 13:22:42 +00:00
|
|
|
val: get_full_help(
|
|
|
|
&To.signature(),
|
|
|
|
&To.examples(),
|
|
|
|
engine_state,
|
|
|
|
stack,
|
|
|
|
self.is_parser_keyword(),
|
|
|
|
),
|
2022-10-21 17:08:57 +00:00
|
|
|
span: call.head,
|
|
|
|
}
|
|
|
|
.into_pipeline_data())
|
2021-10-29 06:26:29 +00:00
|
|
|
}
|
|
|
|
}
|