forked from extern/nushell
remove def-env
and export def-env
(#10999)
follow-up to - https://github.com/nushell/nushell/pull/10715 > **Important** > wait for between 0.87 and 0.88 to land this # Description it's time for removal again 😋 this PR removes `def-env` and `export def-env` in favor of `def --env` # User-Facing Changes `def-env` and `export def-env` will not be found anymore. # Tests + Formatting # After Submitting
This commit is contained in:
@ -1,65 +0,0 @@
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Type, Value,
|
||||
};
|
||||
|
||||
#[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")
|
||||
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
|
||||
.required("def_name", SyntaxShape::String, "definition name")
|
||||
.required("params", SyntaxShape::Signature, "parameters")
|
||||
.required("block", SyntaxShape::Block, "body of the definition")
|
||||
.category(Category::Core)
|
||||
}
|
||||
|
||||
fn extra_usage(&self) -> &str {
|
||||
r#"This command is a parser keyword. For details, check:
|
||||
https://www.nushell.sh/book/thinking_in_nu.html
|
||||
"#
|
||||
}
|
||||
|
||||
fn is_parser_keyword(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn run(
|
||||
&self,
|
||||
engine_state: &EngineState,
|
||||
_stack: &mut Stack,
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
nu_protocol::report_error_new(
|
||||
engine_state,
|
||||
&ShellError::GenericError(
|
||||
"Deprecated command".into(),
|
||||
"`def-env` is deprecated and will be removed in 0.88.".into(),
|
||||
Some(call.head),
|
||||
Some("Use `def --env` instead".into()),
|
||||
vec![],
|
||||
),
|
||||
);
|
||||
Ok(PipelineData::empty())
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![Example {
|
||||
description: "Set environment variable by call a custom command",
|
||||
example: r#"def-env foo [] { $env.BAR = "BAZ" }; foo; $env.BAR"#,
|
||||
result: Some(Value::test_string("BAZ")),
|
||||
}]
|
||||
}
|
||||
}
|
@ -1,94 +0,0 @@
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Type, Value,
|
||||
};
|
||||
|
||||
#[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")
|
||||
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
|
||||
.required("name", SyntaxShape::String, "definition name")
|
||||
.required("params", SyntaxShape::Signature, "parameters")
|
||||
.required("block", SyntaxShape::Block, "body of the definition")
|
||||
.category(Category::Core)
|
||||
}
|
||||
|
||||
fn extra_usage(&self) -> &str {
|
||||
r#"This command is a parser keyword. For details, check:
|
||||
https://www.nushell.sh/book/thinking_in_nu.html
|
||||
|
||||
=== EXTRA NOTE ===
|
||||
All blocks are scoped, including variable definition and environment variable changes.
|
||||
|
||||
Because of this, the following doesn't work:
|
||||
|
||||
export def-env cd_with_fallback [arg = ""] {
|
||||
let fall_back_path = "/tmp"
|
||||
if $arg != "" {
|
||||
cd $arg
|
||||
} else {
|
||||
cd $fall_back_path
|
||||
}
|
||||
}
|
||||
|
||||
Instead, you have to use cd in the top level scope:
|
||||
|
||||
export def-env cd_with_fallback [arg = ""] {
|
||||
let fall_back_path = "/tmp"
|
||||
let path = if $arg != "" {
|
||||
$arg
|
||||
} else {
|
||||
$fall_back_path
|
||||
}
|
||||
cd $path
|
||||
}"#
|
||||
}
|
||||
|
||||
fn is_parser_keyword(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn run(
|
||||
&self,
|
||||
engine_state: &EngineState,
|
||||
_stack: &mut Stack,
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
nu_protocol::report_error_new(
|
||||
engine_state,
|
||||
&ShellError::GenericError(
|
||||
"Deprecated command".into(),
|
||||
"`export def-env` is deprecated and will be removed in 0.88.".into(),
|
||||
Some(call.head),
|
||||
Some("Use `export def --env` instead".into()),
|
||||
vec![],
|
||||
),
|
||||
);
|
||||
Ok(PipelineData::empty())
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![Example {
|
||||
description: "Define a custom command that participates in the environment in a module and call it",
|
||||
example: r#"module foo { export def-env bar [] { $env.FOO_BAR = "BAZ" } }; use foo bar; bar; $env.FOO_BAR"#,
|
||||
result: Some(Value::test_string("BAZ")),
|
||||
}]
|
||||
}
|
||||
|
||||
fn search_terms(&self) -> Vec<&str> {
|
||||
vec!["module"]
|
||||
}
|
||||
}
|
@ -4,7 +4,6 @@ mod collect;
|
||||
mod const_;
|
||||
mod continue_;
|
||||
mod def;
|
||||
mod def_env;
|
||||
mod describe;
|
||||
mod do_;
|
||||
mod echo;
|
||||
@ -13,7 +12,6 @@ mod export;
|
||||
mod export_alias;
|
||||
mod export_const;
|
||||
mod export_def;
|
||||
mod export_def_env;
|
||||
mod export_extern;
|
||||
mod export_module;
|
||||
mod export_use;
|
||||
@ -43,7 +41,6 @@ pub use collect::Collect;
|
||||
pub use const_::Const;
|
||||
pub use continue_::Continue;
|
||||
pub use def::Def;
|
||||
pub use def_env::DefEnv;
|
||||
pub use describe::Describe;
|
||||
pub use do_::Do;
|
||||
pub use echo::Echo;
|
||||
@ -52,7 +49,6 @@ pub use export::ExportCommand;
|
||||
pub use export_alias::ExportAlias;
|
||||
pub use export_const::ExportConst;
|
||||
pub use export_def::ExportDef;
|
||||
pub use export_def_env::ExportDefEnv;
|
||||
pub use export_extern::ExportExtern;
|
||||
pub use export_module::ExportModule;
|
||||
pub use export_use::ExportUse;
|
||||
|
@ -22,7 +22,6 @@ pub fn create_default_context() -> EngineState {
|
||||
Const,
|
||||
Continue,
|
||||
Def,
|
||||
DefEnv,
|
||||
Describe,
|
||||
Do,
|
||||
Echo,
|
||||
@ -31,7 +30,6 @@ pub fn create_default_context() -> EngineState {
|
||||
ExportCommand,
|
||||
ExportConst,
|
||||
ExportDef,
|
||||
ExportDefEnv,
|
||||
ExportExtern,
|
||||
ExportUse,
|
||||
ExportModule,
|
||||
|
@ -14,8 +14,7 @@ mod test_examples {
|
||||
check_example_input_and_output_types_match_command_signature,
|
||||
};
|
||||
use crate::{
|
||||
Break, Collect, Def, DefEnv, Describe, Echo, ExportCommand, ExportDef, ExportDefEnv, If,
|
||||
Let, Module, Mut, Use,
|
||||
Break, Collect, Def, Describe, Echo, ExportCommand, ExportDef, If, Let, Module, Mut, Use,
|
||||
};
|
||||
use nu_protocol::{
|
||||
engine::{Command, EngineState, StateWorkingSet},
|
||||
@ -69,12 +68,10 @@ mod test_examples {
|
||||
working_set.add_decl(Box::new(Break));
|
||||
working_set.add_decl(Box::new(Collect));
|
||||
working_set.add_decl(Box::new(Def));
|
||||
working_set.add_decl(Box::new(DefEnv));
|
||||
working_set.add_decl(Box::new(Describe));
|
||||
working_set.add_decl(Box::new(Echo));
|
||||
working_set.add_decl(Box::new(ExportCommand));
|
||||
working_set.add_decl(Box::new(ExportDef));
|
||||
working_set.add_decl(Box::new(ExportDefEnv));
|
||||
working_set.add_decl(Box::new(If));
|
||||
working_set.add_decl(Box::new(Let));
|
||||
working_set.add_decl(Box::new(Module));
|
||||
|
Reference in New Issue
Block a user