Merge branch 'main' into source-command

This commit is contained in:
Tanishq Kancharla
2021-10-03 14:25:00 -04:00
committed by GitHub
38 changed files with 1168 additions and 126 deletions

View 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 })
}
}

View File

@ -0,0 +1,28 @@
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EvaluationContext};
use nu_protocol::{Signature, SyntaxShape, Value};
pub struct Hide;
impl Command for Hide {
fn name(&self) -> &str {
"hide"
}
fn usage(&self) -> &str {
"Hide definitions in the current scope"
}
fn signature(&self) -> nu_protocol::Signature {
Signature::build("hide").required("pattern", SyntaxShape::String, "import pattern")
}
fn run(
&self,
_context: &EvaluationContext,
call: &Call,
_input: Value,
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
Ok(Value::Nothing { span: call.head })
}
}

View File

@ -1,7 +1,9 @@
mod alias;
mod def;
mod do_;
mod export_def;
mod help;
mod hide;
mod if_;
mod let_;
mod module;
@ -11,7 +13,9 @@ mod use_;
pub use alias::Alias;
pub use def::Def;
pub use do_::Do;
pub use export_def::ExportDef;
pub use help::Help;
pub use hide::Hide;
pub use if_::If;
pub use let_::Let;
pub use module::Module;

View File

@ -14,7 +14,7 @@ impl Command for Use {
}
fn signature(&self) -> nu_protocol::Signature {
Signature::build("use").required("module_name", SyntaxShape::String, "module name")
Signature::build("use").required("pattern", SyntaxShape::String, "import pattern")
}
fn run(