mirror of
https://github.com/nushell/nushell
synced 2025-01-14 14:14:13 +00:00
restrict plugin file name (#6479)
This commit is contained in:
parent
65327e0e7e
commit
a6ba58ec41
1 changed files with 46 additions and 28 deletions
|
@ -3197,37 +3197,55 @@ pub fn parse_register(
|
||||||
nu_engine::env::env_to_strings(working_set.permanent_state, &stack).unwrap_or_default();
|
nu_engine::env::env_to_strings(working_set.permanent_state, &stack).unwrap_or_default();
|
||||||
let error = match signature {
|
let error = match signature {
|
||||||
Some(signature) => arguments.and_then(|(path, encoding)| {
|
Some(signature) => arguments.and_then(|(path, encoding)| {
|
||||||
signature.map(|signature| {
|
// restrict plugin file name starts with `nu_plugin_`
|
||||||
let plugin_decl = PluginDeclaration::new(path, signature, encoding, shell);
|
let f_name = path
|
||||||
working_set.add_decl(Box::new(plugin_decl));
|
.file_name()
|
||||||
working_set.mark_plugins_file_dirty();
|
.map(|s| s.to_string_lossy().starts_with("nu_plugin_"));
|
||||||
})
|
|
||||||
}),
|
|
||||||
None => arguments.and_then(|(path, encoding)| {
|
|
||||||
get_signature(path.as_path(), &encoding, &shell, ¤t_envs)
|
|
||||||
.map_err(|err| {
|
|
||||||
ParseError::LabeledError(
|
|
||||||
"Error getting signatures".into(),
|
|
||||||
err.to_string(),
|
|
||||||
spans[0],
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.map(|signatures| {
|
|
||||||
for signature in signatures {
|
|
||||||
// create plugin command declaration (need struct impl Command)
|
|
||||||
// store declaration in working set
|
|
||||||
let plugin_decl = PluginDeclaration::new(
|
|
||||||
path.clone(),
|
|
||||||
signature,
|
|
||||||
encoding.clone(),
|
|
||||||
shell.clone(),
|
|
||||||
);
|
|
||||||
|
|
||||||
working_set.add_decl(Box::new(plugin_decl));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if let Some(true) = f_name {
|
||||||
|
signature.map(|signature| {
|
||||||
|
let plugin_decl = PluginDeclaration::new(path, signature, encoding, shell);
|
||||||
|
working_set.add_decl(Box::new(plugin_decl));
|
||||||
working_set.mark_plugins_file_dirty();
|
working_set.mark_plugins_file_dirty();
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
None => arguments.and_then(|(path, encoding)| {
|
||||||
|
// restrict plugin file name starts with `nu_plugin_`
|
||||||
|
let f_name = path
|
||||||
|
.file_name()
|
||||||
|
.map(|s| s.to_string_lossy().starts_with("nu_plugin_"));
|
||||||
|
|
||||||
|
if let Some(true) = f_name {
|
||||||
|
get_signature(path.as_path(), &encoding, &shell, ¤t_envs)
|
||||||
|
.map_err(|err| {
|
||||||
|
ParseError::LabeledError(
|
||||||
|
"Error getting signatures".into(),
|
||||||
|
err.to_string(),
|
||||||
|
spans[0],
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.map(|signatures| {
|
||||||
|
for signature in signatures {
|
||||||
|
// create plugin command declaration (need struct impl Command)
|
||||||
|
// store declaration in working set
|
||||||
|
let plugin_decl = PluginDeclaration::new(
|
||||||
|
path.clone(),
|
||||||
|
signature,
|
||||||
|
encoding.clone(),
|
||||||
|
shell.clone(),
|
||||||
|
);
|
||||||
|
|
||||||
|
working_set.add_decl(Box::new(plugin_decl));
|
||||||
|
}
|
||||||
|
|
||||||
|
working_set.mark_plugins_file_dirty();
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
.err();
|
.err();
|
||||||
|
|
Loading…
Reference in a new issue