forked from extern/nushell
Add 'export def' command
This commit is contained in:
@ -6,7 +6,7 @@ use nu_protocol::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
Alias, Benchmark, BuildString, Def, Do, Each, External, For, From, FromJson, Git, GitCheckout,
|
||||
Alias, Benchmark, BuildString, Def, Do, Each, ExportDef, External, For, From, FromJson, Git, GitCheckout,
|
||||
If, Length, Let, LetEnv, Lines, ListGitBranches, Ls, Module, Sys, Table, Use, Where,
|
||||
};
|
||||
|
||||
@ -20,12 +20,20 @@ pub fn create_default_context() -> Rc<RefCell<EngineState>> {
|
||||
Signature::build("where").required("cond", SyntaxShape::RowCondition, "condition");
|
||||
working_set.add_decl(sig.predeclare());
|
||||
|
||||
working_set.add_decl(Box::new(If));
|
||||
|
||||
working_set.add_decl(Box::new(Let));
|
||||
|
||||
working_set.add_decl(Box::new(LetEnv));
|
||||
|
||||
working_set.add_decl(Box::new(Alias));
|
||||
working_set.add_decl(Box::new(Benchmark));
|
||||
working_set.add_decl(Box::new(BuildString));
|
||||
|
||||
working_set.add_decl(Box::new(Def));
|
||||
working_set.add_decl(Box::new(Do));
|
||||
working_set.add_decl(Box::new(Each));
|
||||
working_set.add_decl(Box::new(ExportDef));
|
||||
working_set.add_decl(Box::new(External));
|
||||
working_set.add_decl(Box::new(For));
|
||||
working_set.add_decl(Box::new(From));
|
||||
|
35
crates/nu-command/src/export_def.rs
Normal file
35
crates/nu-command/src/export_def.rs
Normal file
@ -0,0 +1,35 @@
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EvaluationContext};
|
||||
use nu_protocol::{Signature, SyntaxShape, Value};
|
||||
|
||||
pub struct ExportDef;
|
||||
|
||||
impl Command for ExportDef {
|
||||
fn name(&self) -> &str {
|
||||
"export def"
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
"Define a custom command and export it from a module"
|
||||
}
|
||||
|
||||
fn signature(&self) -> nu_protocol::Signature {
|
||||
Signature::build("export def")
|
||||
.required("target", SyntaxShape::String, "definition name")
|
||||
.required("params", SyntaxShape::Signature, "parameters")
|
||||
.required(
|
||||
"block",
|
||||
SyntaxShape::Block(Some(vec![])),
|
||||
"body of the definition",
|
||||
)
|
||||
}
|
||||
|
||||
fn run(
|
||||
&self,
|
||||
_context: &EvaluationContext,
|
||||
call: &Call,
|
||||
_input: Value,
|
||||
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
|
||||
Ok(Value::Nothing { span: call.head })
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user