Add support for def-env and export def-env (#887)

This commit is contained in:
JT
2022-01-29 15:45:46 -05:00
committed by GitHub
parent bffb4950c2
commit 44821d9941
9 changed files with 194 additions and 6 deletions

View File

@ -0,0 +1,38 @@
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Category, PipelineData, Signature, SyntaxShape};
#[derive(Clone)]
pub struct DefEnv;
impl Command for DefEnv {
fn name(&self) -> &str {
"def-env"
}
fn usage(&self) -> &str {
"Define a custom command, which participates in the caller environment"
}
fn signature(&self) -> nu_protocol::Signature {
Signature::build("def-env")
.required("def_name", SyntaxShape::String, "definition name")
.required("params", SyntaxShape::Signature, "parameters")
.required(
"block",
SyntaxShape::Block(Some(vec![])),
"body of the definition",
)
.category(Category::Core)
}
fn run(
&self,
_engine_state: &EngineState,
_stack: &mut Stack,
call: &Call,
_input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
Ok(PipelineData::new(call.head))
}
}

View File

@ -0,0 +1,38 @@
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Category, PipelineData, Signature, SyntaxShape};
#[derive(Clone)]
pub struct ExportDefEnv;
impl Command for ExportDefEnv {
fn name(&self) -> &str {
"export def-env"
}
fn usage(&self) -> &str {
"Define a custom command that participates in the environment and export it from a module"
}
fn signature(&self) -> nu_protocol::Signature {
Signature::build("export def-env")
.required("name", SyntaxShape::String, "definition name")
.required("params", SyntaxShape::Signature, "parameters")
.required(
"block",
SyntaxShape::Block(Some(vec![])),
"body of the definition",
)
.category(Category::Core)
}
fn run(
&self,
_engine_state: &EngineState,
_stack: &mut Stack,
call: &Call,
_input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
Ok(PipelineData::new(call.head))
}
}

View File

@ -1,11 +1,13 @@
mod alias;
mod debug;
mod def;
mod def_env;
mod describe;
mod do_;
mod echo;
mod export;
mod export_def;
mod export_def_env;
mod export_env;
mod for_;
mod help;
@ -24,11 +26,13 @@ mod version;
pub use alias::Alias;
pub use debug::Debug;
pub use def::Def;
pub use def_env::DefEnv;
pub use describe::Describe;
pub use do_::Do;
pub use echo::Echo;
pub use export::ExportCommand;
pub use export_def::ExportDef;
pub use export_def_env::ExportDefEnv;
pub use export_env::ExportEnv;
pub use for_::For;
pub use help::Help;