1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
use crate::engine::{EngineState, Stack};
use crate::PipelineData;
use crate::{
ast::{Call, Expression},
engine::Command,
BlockId, Example, ShellError, Signature,
};
use std::path::PathBuf;
#[derive(Clone)]
pub struct Alias {
pub name: String,
pub command: Option<Box<dyn Command>>, pub wrapped_call: Expression,
}
impl Command for Alias {
fn name(&self) -> &str {
&self.name
}
fn signature(&self) -> Signature {
if let Some(cmd) = &self.command {
cmd.signature()
} else {
Signature::new(&self.name).allows_unknown_args()
}
}
fn usage(&self) -> &str {
if let Some(cmd) = &self.command {
cmd.usage()
} else {
"This alias wraps an unknown external command."
}
}
fn extra_usage(&self) -> &str {
if let Some(cmd) = &self.command {
cmd.extra_usage()
} else {
""
}
}
fn run(
&self,
_engine_state: &EngineState,
_stack: &mut Stack,
call: &Call,
_input: PipelineData,
) -> Result<PipelineData, ShellError> {
Err(ShellError::NushellFailedSpanned {
msg: "Can't run alias directly. Unwrap it first".to_string(),
label: "originates from here".to_string(),
span: call.head,
})
}
fn examples(&self) -> Vec<Example> {
if let Some(cmd) = &self.command {
cmd.examples()
} else {
vec![]
}
}
fn is_builtin(&self) -> bool {
if let Some(cmd) = &self.command {
cmd.is_builtin()
} else {
false
}
}
fn is_known_external(&self) -> bool {
if let Some(cmd) = &self.command {
cmd.is_known_external()
} else {
false
}
}
fn is_alias(&self) -> bool {
true
}
fn as_alias(&self) -> Option<&Alias> {
Some(self)
}
fn is_custom_command(&self) -> bool {
if let Some(cmd) = &self.command {
cmd.is_custom_command()
} else if self.get_block_id().is_some() {
true
} else {
self.is_known_external()
}
}
fn is_sub(&self) -> bool {
if let Some(cmd) = &self.command {
cmd.is_sub()
} else {
self.name().contains(' ')
}
}
fn is_parser_keyword(&self) -> bool {
if let Some(cmd) = &self.command {
cmd.is_parser_keyword()
} else {
false
}
}
fn is_plugin(&self) -> Option<(&PathBuf, &Option<PathBuf>)> {
if let Some(cmd) = &self.command {
cmd.is_plugin()
} else {
None
}
}
fn get_block_id(&self) -> Option<BlockId> {
if let Some(cmd) = &self.command {
cmd.get_block_id()
} else {
None
}
}
fn search_terms(&self) -> Vec<&str> {
if let Some(cmd) = &self.command {
cmd.search_terms()
} else {
vec![]
}
}
}