Allow exporting extern-wrapped (#10025)

This commit is contained in:
Jakub Žádník
2023-08-18 20:45:33 +03:00
committed by GitHub
parent fe2c498a81
commit cdf09abcc0
6 changed files with 115 additions and 17 deletions

View File

@ -0,0 +1,56 @@
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> {
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"]
}
}

View File

@ -15,6 +15,7 @@ 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_;
@ -55,6 +56,7 @@ 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;