mirror of
https://github.com/nushell/nushell.git
synced 2024-12-23 23:49:44 +01:00
remove extern-wrapped
and export extern-wrapped
(#11000)
follow-up to - https://github.com/nushell/nushell/pull/10716 > **Important** > wait for between 0.87 and 0.88 to land this # Description it's time for removal again 😋 this PR removes `extern-wrapped` and `export extern-wrapped` in favor of `def --wrapped` # User-Facing Changes `extern-wrapped` and `export extern-wrapped` will not be found anymore. # Tests + Formatting # After Submitting
This commit is contained in:
parent
e93e51d672
commit
e0c8a3d14c
@ -1,66 +0,0 @@
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Type};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ExportExternWrapped;
|
||||
|
||||
impl Command for ExportExternWrapped {
|
||||
fn name(&self) -> &str {
|
||||
"export extern-wrapped"
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
"Define an extern with a custom code block and export it from a module."
|
||||
}
|
||||
|
||||
fn signature(&self) -> nu_protocol::Signature {
|
||||
Signature::build("export extern-wrapped")
|
||||
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
|
||||
.required("def_name", SyntaxShape::String, "definition name")
|
||||
.required("params", SyntaxShape::Signature, "parameters")
|
||||
.required("body", SyntaxShape::Block, "wrapper code block")
|
||||
.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(),
|
||||
"`export extern-wrapped` is deprecated and will be removed in 0.88.".into(),
|
||||
Some(call.head),
|
||||
Some("Use `export def --wrapped` instead".into()),
|
||||
vec![],
|
||||
),
|
||||
);
|
||||
Ok(PipelineData::empty())
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![Example {
|
||||
description: "Export the signature for an external command",
|
||||
example: r#"export extern-wrapped my-echo [...rest] { echo $rest }"#,
|
||||
result: None,
|
||||
}]
|
||||
}
|
||||
|
||||
fn search_terms(&self) -> Vec<&str> {
|
||||
vec!["signature", "module", "declare"]
|
||||
}
|
||||
}
|
@ -1,75 +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 ExternWrapped;
|
||||
|
||||
impl Command for ExternWrapped {
|
||||
fn name(&self) -> &str {
|
||||
"extern-wrapped"
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
"Define a signature for an external command with a custom code block."
|
||||
}
|
||||
|
||||
fn signature(&self) -> nu_protocol::Signature {
|
||||
Signature::build("extern-wrapped")
|
||||
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
|
||||
.allow_variants_without_examples(true)
|
||||
.required("def_name", SyntaxShape::String, "definition name")
|
||||
.required("params", SyntaxShape::Signature, "parameters")
|
||||
.required("body", SyntaxShape::Block, "wrapper code block")
|
||||
.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(),
|
||||
"`extern-wrapped` is deprecated and will be removed in 0.88.".into(),
|
||||
Some(call.head),
|
||||
Some("Use `def --wrapped` instead".into()),
|
||||
vec![],
|
||||
),
|
||||
);
|
||||
Ok(PipelineData::empty())
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![Example {
|
||||
description: "Define a custom wrapper for an external command",
|
||||
example: r#"extern-wrapped my-echo [...rest] { echo $rest }; my-echo spam"#,
|
||||
result: Some(Value::test_list(vec![Value::test_string("spam")])),
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
#[test]
|
||||
fn test_examples() {
|
||||
use super::ExternWrapped;
|
||||
use crate::test_examples;
|
||||
test_examples(ExternWrapped {})
|
||||
}
|
||||
}
|
@ -15,11 +15,9 @@ mod export_const;
|
||||
mod export_def;
|
||||
mod export_def_env;
|
||||
mod export_extern;
|
||||
mod export_extern_wrapped;
|
||||
mod export_module;
|
||||
mod export_use;
|
||||
mod extern_;
|
||||
mod extern_wrapped;
|
||||
mod for_;
|
||||
mod hide;
|
||||
mod hide_env;
|
||||
@ -56,11 +54,9 @@ pub use export_const::ExportConst;
|
||||
pub use export_def::ExportDef;
|
||||
pub use export_def_env::ExportDefEnv;
|
||||
pub use export_extern::ExportExtern;
|
||||
pub use export_extern_wrapped::ExportExternWrapped;
|
||||
pub use export_module::ExportModule;
|
||||
pub use export_use::ExportUse;
|
||||
pub use extern_::Extern;
|
||||
pub use extern_wrapped::ExternWrapped;
|
||||
pub use for_::For;
|
||||
pub use hide::Hide;
|
||||
pub use hide_env::HideEnv;
|
||||
|
@ -33,11 +33,9 @@ pub fn create_default_context() -> EngineState {
|
||||
ExportDef,
|
||||
ExportDefEnv,
|
||||
ExportExtern,
|
||||
ExportExternWrapped,
|
||||
ExportUse,
|
||||
ExportModule,
|
||||
Extern,
|
||||
ExternWrapped,
|
||||
For,
|
||||
Hide,
|
||||
HideEnv,
|
||||
|
@ -47,9 +47,7 @@ pub const UNALIASABLE_PARSER_KEYWORDS: &[&[u8]] = &[
|
||||
b"export def",
|
||||
b"for",
|
||||
b"extern",
|
||||
b"extern-wrapped",
|
||||
b"export extern",
|
||||
b"export extern-wrapped",
|
||||
b"alias",
|
||||
b"export alias",
|
||||
b"export-env",
|
||||
@ -151,11 +149,7 @@ pub fn parse_def_predecl(working_set: &mut StateWorkingSet, spans: &[Span]) {
|
||||
return;
|
||||
};
|
||||
|
||||
if def_type_name != b"def"
|
||||
&& def_type_name != b"def-env"
|
||||
&& def_type_name != b"extern"
|
||||
&& def_type_name != b"extern-wrapped"
|
||||
{
|
||||
if def_type_name != b"def" && def_type_name != b"def-env" && def_type_name != b"extern" {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -635,9 +629,9 @@ pub fn parse_extern(
|
||||
};
|
||||
|
||||
let extern_call = working_set.get_span_contents(name_span).to_vec();
|
||||
if extern_call != b"extern" && extern_call != b"extern-wrapped" {
|
||||
if extern_call != b"extern" {
|
||||
working_set.error(ParseError::UnknownState(
|
||||
"internal error: Wrong call name for extern or extern-wrapped command".into(),
|
||||
"internal error: Wrong call name for extern command".into(),
|
||||
span(spans),
|
||||
));
|
||||
return garbage_pipeline(spans);
|
||||
@ -1055,8 +1049,9 @@ pub fn parse_export_in_block(
|
||||
let full_name = if lite_command.parts.len() > 1 {
|
||||
let sub = working_set.get_span_contents(lite_command.parts[1]);
|
||||
match sub {
|
||||
b"alias" | b"def" | b"def-env" | b"extern" | b"extern-wrapped" | b"use" | b"module"
|
||||
| b"const" => [b"export ", sub].concat(),
|
||||
b"alias" | b"def" | b"def-env" | b"extern" | b"use" | b"module" | b"const" => {
|
||||
[b"export ", sub].concat()
|
||||
}
|
||||
_ => b"export".to_vec(),
|
||||
}
|
||||
} else {
|
||||
@ -1121,7 +1116,6 @@ pub fn parse_export_in_block(
|
||||
}
|
||||
b"export module" => parse_module(working_set, lite_command, None).0,
|
||||
b"export extern" => parse_extern(working_set, lite_command, None),
|
||||
b"export extern-wrapped" => parse_extern(working_set, lite_command, None),
|
||||
_ => {
|
||||
working_set.error(ParseError::UnexpectedKeyword(
|
||||
String::from_utf8_lossy(&full_name).to_string(),
|
||||
@ -1290,7 +1284,7 @@ pub fn parse_export_in_module(
|
||||
|
||||
result
|
||||
}
|
||||
b"extern" | b"extern-wrapped" => {
|
||||
b"extern" => {
|
||||
let lite_command = LiteCommand {
|
||||
comments: lite_command.comments.clone(),
|
||||
parts: spans[1..].to_vec(),
|
||||
@ -1303,7 +1297,7 @@ pub fn parse_export_in_module(
|
||||
id
|
||||
} else {
|
||||
working_set.error(ParseError::InternalError(
|
||||
"missing 'export extern' or 'export extern-wrapped' command".into(),
|
||||
"missing 'export extern' command".into(),
|
||||
export_span,
|
||||
));
|
||||
return (garbage_pipeline(spans), vec![]);
|
||||
@ -1569,7 +1563,7 @@ pub fn parse_export_in_module(
|
||||
}
|
||||
_ => {
|
||||
working_set.error(ParseError::Expected(
|
||||
"def, def-env, alias, use, module, const, extern or extern-wrapped keyword",
|
||||
"def, def-env, alias, use, module, const or extern keyword",
|
||||
spans[1],
|
||||
));
|
||||
|
||||
@ -1578,9 +1572,9 @@ pub fn parse_export_in_module(
|
||||
}
|
||||
} else {
|
||||
working_set.error(ParseError::MissingPositional(
|
||||
"def, def-env, alias, use, module, const, extern or extern-wrapped keyword".to_string(),
|
||||
"def, def-env, alias, use, module, const or extern keyword".to_string(),
|
||||
Span::new(export_span.end, export_span.end),
|
||||
"def, def-env, alias, use, module, const, extern or extern-wrapped keyword".to_string(),
|
||||
"def, def-env, alias, use, module, const or extern keyword".to_string(),
|
||||
));
|
||||
|
||||
vec![]
|
||||
@ -1762,11 +1756,9 @@ pub fn parse_module_block(
|
||||
b"const" => block
|
||||
.pipelines
|
||||
.push(parse_const(working_set, &command.parts)),
|
||||
b"extern" | b"extern-wrapped" => {
|
||||
block
|
||||
.pipelines
|
||||
.push(parse_extern(working_set, command, None))
|
||||
}
|
||||
b"extern" => block
|
||||
.pipelines
|
||||
.push(parse_extern(working_set, command, None)),
|
||||
b"alias" => {
|
||||
block.pipelines.push(parse_alias(
|
||||
working_set,
|
||||
@ -1906,7 +1898,7 @@ pub fn parse_module_block(
|
||||
}
|
||||
_ => {
|
||||
working_set.error(ParseError::ExpectedKeyword(
|
||||
"def, const, def-env, extern, extern-wrapped, alias, use, module, export or export-env keyword".into(),
|
||||
"def, const, def-env, extern, alias, use, module, export or export-env keyword".into(),
|
||||
command.parts[0],
|
||||
));
|
||||
|
||||
|
@ -4918,8 +4918,8 @@ pub fn parse_expression(
|
||||
|
||||
// For now, check for special parses of certain keywords
|
||||
match bytes.as_slice() {
|
||||
b"def" | b"extern" | b"extern-wrapped" | b"for" | b"module" | b"use" | b"source"
|
||||
| b"alias" | b"export" | b"hide" => {
|
||||
b"def" | b"extern" | b"for" | b"module" | b"use" | b"source" | b"alias" | b"export"
|
||||
| b"hide" => {
|
||||
working_set.error(ParseError::BuiltinCommandInPipeline(
|
||||
String::from_utf8(bytes)
|
||||
.expect("builtin commands bytes should be able to convert to string"),
|
||||
@ -5086,7 +5086,7 @@ pub fn parse_builtin_commands(
|
||||
|
||||
match name {
|
||||
b"def" | b"def-env" => parse_def(working_set, lite_command, None).0,
|
||||
b"extern" | b"extern-wrapped" => parse_extern(working_set, lite_command, None),
|
||||
b"extern" => parse_extern(working_set, lite_command, None),
|
||||
b"let" => parse_let(working_set, &lite_command.parts),
|
||||
b"const" => parse_const(working_set, &lite_command.parts),
|
||||
b"mut" => parse_mut(working_set, &lite_command.parts),
|
||||
|
Loading…
Reference in New Issue
Block a user