mirror of
https://github.com/nushell/nushell
synced 2024-12-27 05:23:11 +00:00
Add a module command
This commit is contained in:
parent
a176f12c9e
commit
e9f1575924
3 changed files with 32 additions and 7 deletions
|
@ -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,
|
||||
};
|
||||
|
||||
pub fn create_default_context() -> Rc<RefCell<EngineState>> {
|
||||
|
@ -46,6 +46,8 @@ 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(Table));
|
||||
|
||||
working_set.add_decl(Box::new(External));
|
||||
|
|
|
@ -16,6 +16,7 @@ mod lines;
|
|||
mod list_git_branches;
|
||||
mod ls;
|
||||
mod run_external;
|
||||
mod module;
|
||||
mod table;
|
||||
mod where_;
|
||||
|
||||
|
@ -37,4 +38,5 @@ pub use lines::Lines;
|
|||
pub use list_git_branches::ListGitBranches;
|
||||
pub use ls::Ls;
|
||||
pub use run_external::External;
|
||||
pub use module::Module;
|
||||
pub use table::Table;
|
||||
|
|
|
@ -2747,13 +2747,34 @@ pub fn parse_module(
|
|||
|
||||
working_set.exit_scope();
|
||||
|
||||
// WIP error:
|
||||
let block_id = working_set.add_block(block);
|
||||
|
||||
let block_expr = Expression {
|
||||
expr: Expr::Block(block_id),
|
||||
span: block_span,
|
||||
ty: Type::Block,
|
||||
custom_completion: None,
|
||||
};
|
||||
|
||||
let module_decl_id = working_set
|
||||
.find_decl(b"module")
|
||||
.expect("internal error: missing module command");
|
||||
|
||||
let call = Box::new(Call {
|
||||
head: spans[0],
|
||||
decl_id: module_decl_id,
|
||||
positional: vec![name_expr, block_expr],
|
||||
named: vec![],
|
||||
});
|
||||
|
||||
(
|
||||
garbage_statement(spans),
|
||||
Some(ParseError::UnknownState(
|
||||
"This is OK module".into(),
|
||||
span(spans),
|
||||
)),
|
||||
Statement::Pipeline(Pipeline::from_vec(vec![Expression {
|
||||
expr: Expr::Call(call),
|
||||
span: span(spans),
|
||||
ty: Type::Unknown,
|
||||
custom_completion: None,
|
||||
}])),
|
||||
error,
|
||||
)
|
||||
} else {
|
||||
(
|
||||
|
|
Loading…
Reference in a new issue