forked from extern/nushell
Merge pull request #69 from kubouch/simple-module
Primitive module implementation
This commit is contained in:
@ -7,7 +7,7 @@ use nu_protocol::{
|
||||
|
||||
use crate::{
|
||||
where_::Where, Alias, Benchmark, BuildString, Def, Do, Each, External, For, Git, GitCheckout,
|
||||
If, Length, Let, LetEnv, Lines, ListGitBranches, Ls, Table,
|
||||
If, Length, Let, LetEnv, Lines, ListGitBranches, Ls, Module, Table, Use,
|
||||
};
|
||||
|
||||
pub fn create_default_context() -> Rc<RefCell<EngineState>> {
|
||||
@ -46,6 +46,10 @@ pub fn create_default_context() -> Rc<RefCell<EngineState>> {
|
||||
|
||||
working_set.add_decl(Box::new(Ls));
|
||||
|
||||
working_set.add_decl(Box::new(Module));
|
||||
|
||||
working_set.add_decl(Box::new(Use));
|
||||
|
||||
working_set.add_decl(Box::new(Table));
|
||||
|
||||
working_set.add_decl(Box::new(External));
|
||||
|
@ -15,8 +15,10 @@ mod let_env;
|
||||
mod lines;
|
||||
mod list_git_branches;
|
||||
mod ls;
|
||||
mod module;
|
||||
mod run_external;
|
||||
mod table;
|
||||
mod use_;
|
||||
mod where_;
|
||||
|
||||
pub use alias::Alias;
|
||||
@ -36,5 +38,7 @@ pub use let_env::LetEnv;
|
||||
pub use lines::Lines;
|
||||
pub use list_git_branches::ListGitBranches;
|
||||
pub use ls::Ls;
|
||||
pub use module::Module;
|
||||
pub use run_external::External;
|
||||
pub use table::Table;
|
||||
pub use use_::Use;
|
||||
|
34
crates/nu-command/src/module.rs
Normal file
34
crates/nu-command/src/module.rs
Normal file
@ -0,0 +1,34 @@
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EvaluationContext};
|
||||
use nu_protocol::{Signature, SyntaxShape, Value};
|
||||
|
||||
pub struct Module;
|
||||
|
||||
impl Command for Module {
|
||||
fn name(&self) -> &str {
|
||||
"module"
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
"Define a custom module"
|
||||
}
|
||||
|
||||
fn signature(&self) -> nu_protocol::Signature {
|
||||
Signature::build("module")
|
||||
.required("module_name", SyntaxShape::String, "module name")
|
||||
.required(
|
||||
"block",
|
||||
SyntaxShape::Block(Some(vec![])),
|
||||
"body of the module",
|
||||
)
|
||||
}
|
||||
|
||||
fn run(
|
||||
&self,
|
||||
_context: &EvaluationContext,
|
||||
call: &Call,
|
||||
_input: Value,
|
||||
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
|
||||
Ok(Value::Nothing { span: call.head })
|
||||
}
|
||||
}
|
28
crates/nu-command/src/use_.rs
Normal file
28
crates/nu-command/src/use_.rs
Normal file
@ -0,0 +1,28 @@
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EvaluationContext};
|
||||
use nu_protocol::{Signature, SyntaxShape, Value};
|
||||
|
||||
pub struct Use;
|
||||
|
||||
impl Command for Use {
|
||||
fn name(&self) -> &str {
|
||||
"use"
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
"Use definitions from a module"
|
||||
}
|
||||
|
||||
fn signature(&self) -> nu_protocol::Signature {
|
||||
Signature::build("use").required("module_name", SyntaxShape::String, "module name")
|
||||
}
|
||||
|
||||
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