Start parsing 'use'; Add Use command

This commit is contained in:
Jakub Žádník
2021-09-26 13:25:52 +03:00
parent 57a07385ac
commit 9e176674a5
6 changed files with 117 additions and 1 deletions

View File

@ -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, Module, Table,
If, Length, Let, LetEnv, Lines, ListGitBranches, Ls, Module, Table, Use,
};
pub fn create_default_context() -> Rc<RefCell<EngineState>> {
@ -48,6 +48,8 @@ pub fn create_default_context() -> Rc<RefCell<EngineState>> {
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));

View File

@ -18,6 +18,7 @@ mod ls;
mod module;
mod run_external;
mod table;
mod use_;
mod where_;
pub use alias::Alias;
@ -40,3 +41,4 @@ pub use ls::Ls;
pub use module::Module;
pub use run_external::External;
pub use table::Table;
pub use use_::Use;

View File

@ -0,0 +1,29 @@
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 })
}
}