2021-09-08 04:26:57 +02:00
|
|
|
use crate::{ast::Call, value::Value, BlockId, Example, ShellError, Signature};
|
2021-09-02 20:21:37 +02:00
|
|
|
|
2021-09-03 00:58:15 +02:00
|
|
|
use super::EvaluationContext;
|
2021-09-02 10:25:22 +02:00
|
|
|
|
|
|
|
pub trait Command {
|
|
|
|
fn name(&self) -> &str;
|
|
|
|
|
|
|
|
fn signature(&self) -> Signature {
|
|
|
|
Signature::new(self.name()).desc(self.usage()).filter()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn usage(&self) -> &str;
|
|
|
|
|
|
|
|
fn extra_usage(&self) -> &str {
|
|
|
|
""
|
|
|
|
}
|
|
|
|
|
2021-09-03 00:58:15 +02:00
|
|
|
fn run(
|
|
|
|
&self,
|
|
|
|
context: &EvaluationContext,
|
|
|
|
call: &Call,
|
|
|
|
input: Value,
|
|
|
|
) -> Result<Value, ShellError>;
|
2021-09-02 10:25:22 +02:00
|
|
|
|
|
|
|
fn is_binary(&self) -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Commands that are not meant to be run by users
|
|
|
|
fn is_private(&self) -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
|
|
|
fn examples(&self) -> Vec<Example> {
|
|
|
|
Vec::new()
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is a built-in command
|
|
|
|
fn is_builtin(&self) -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
|
|
|
// Is a sub command
|
|
|
|
fn is_sub(&self) -> bool {
|
|
|
|
self.name().contains(' ')
|
|
|
|
}
|
|
|
|
|
|
|
|
// Is a plugin command
|
|
|
|
fn is_plugin(&self) -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
2021-09-06 01:16:27 +02:00
|
|
|
// If command is a block i.e. def blah [] { }, get the block id
|
|
|
|
fn get_block_id(&self) -> Option<BlockId> {
|
2021-09-02 20:21:37 +02:00
|
|
|
None
|
2021-09-02 10:25:22 +02:00
|
|
|
}
|
|
|
|
}
|