mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 10:15:41 +02:00
Add support for def-env
and export def-env
(#887)
This commit is contained in:
38
crates/nu-command/src/core_commands/def_env.rs
Normal file
38
crates/nu-command/src/core_commands/def_env.rs
Normal 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))
|
||||
}
|
||||
}
|
38
crates/nu-command/src/core_commands/export_def_env.rs
Normal file
38
crates/nu-command/src/core_commands/export_def_env.rs
Normal 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))
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -28,11 +28,13 @@ pub fn create_default_context(cwd: impl AsRef<Path>) -> EngineState {
|
||||
Alias,
|
||||
Debug,
|
||||
Def,
|
||||
DefEnv,
|
||||
Describe,
|
||||
Do,
|
||||
Echo,
|
||||
ExportCommand,
|
||||
ExportDef,
|
||||
ExportDefEnv,
|
||||
ExportEnv,
|
||||
For,
|
||||
Help,
|
||||
|
Reference in New Issue
Block a user