nushell/crates/nu-command/src/core_commands/alias.rs

67 lines
2.0 KiB
Rust
Raw Normal View History

2021-09-29 20:25:05 +02:00
use nu_protocol::ast::Call;
2021-10-25 18:58:58 +02:00
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Category, Example, PipelineData, Signature, Span, SyntaxShape, Type, Value};
2021-09-29 20:25:05 +02:00
2021-10-25 06:01:02 +02:00
#[derive(Clone)]
2021-09-29 20:25:05 +02:00
pub struct Alias;
impl Command for Alias {
fn name(&self) -> &str {
"alias"
}
fn usage(&self) -> &str {
"Alias a command (with optional flags) to a new name"
}
fn signature(&self) -> nu_protocol::Signature {
Signature::build("alias")
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
2021-09-29 20:25:05 +02:00
.required("name", SyntaxShape::String, "name of the alias")
.required(
"initial_value",
SyntaxShape::Keyword(b"=".to_vec(), Box::new(SyntaxShape::Expression)),
"equals sign followed by value",
)
.category(Category::Core)
2021-09-29 20:25:05 +02:00
}
fn extra_usage(&self) -> &str {
r#"This command is a parser keyword. For details, check:
https://www.nushell.sh/book/thinking_in_nu.html"#
}
fn is_parser_keyword(&self) -> bool {
true
}
2022-06-08 13:22:53 +02:00
fn search_terms(&self) -> Vec<&str> {
vec!["abbr", "aka", "fn", "func", "function"]
}
2021-09-29 20:25:05 +02:00
fn run(
&self,
2021-10-25 08:31:39 +02:00
_engine_state: &EngineState,
_stack: &mut Stack,
call: &Call,
2021-10-25 06:01:02 +02:00
_input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
Ok(PipelineData::new(call.head))
2021-09-29 20:25:05 +02:00
}
fn examples(&self) -> Vec<Example> {
2022-10-26 18:36:42 +02:00
vec![
Example {
description: "Alias ll to ls -l",
example: "alias ll = ls -l",
result: Some(Value::nothing(Span::test_data())),
2022-10-26 18:36:42 +02:00
},
Example {
description: "Make an alias that makes a list of all custom commands",
example: "alias customs = ($nu.scope.commands | where is_custom | get command)",
result: Some(Value::nothing(Span::test_data())),
2022-10-26 18:36:42 +02:00
},
]
}
2021-09-29 20:25:05 +02:00
}