mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 14:40:06 +02:00
Rename overlay commands (#6375)
* rename from overlay add to overlay use * rename from overlay remove to overlay hide * rename add to use_
This commit is contained in:
@ -4,20 +4,20 @@ use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Spanned, SyntaxShape};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct OverlayRemove;
|
||||
pub struct OverlayHide;
|
||||
|
||||
impl Command for OverlayRemove {
|
||||
impl Command for OverlayHide {
|
||||
fn name(&self) -> &str {
|
||||
"overlay remove"
|
||||
"overlay hide"
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
"Remove an active overlay"
|
||||
"Hide an active overlay"
|
||||
}
|
||||
|
||||
fn signature(&self) -> nu_protocol::Signature {
|
||||
Signature::build("overlay remove")
|
||||
.optional("name", SyntaxShape::String, "Overlay to remove")
|
||||
Signature::build("overlay hide")
|
||||
.optional("name", SyntaxShape::String, "Overlay to hide")
|
||||
.switch(
|
||||
"keep-custom",
|
||||
"Keep all newly added symbols within the next activated overlay",
|
||||
@ -26,7 +26,7 @@ impl Command for OverlayRemove {
|
||||
.named(
|
||||
"keep-env",
|
||||
SyntaxShape::List(Box::new(SyntaxShape::String)),
|
||||
"List of environment variables to keep from the removed overlay",
|
||||
"List of environment variables to keep from the hidden overlay",
|
||||
Some('e'),
|
||||
)
|
||||
.category(Category::Core)
|
||||
@ -110,31 +110,31 @@ impl Command for OverlayRemove {
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![
|
||||
Example {
|
||||
description: "Remove an overlay created from a module",
|
||||
description: "Hide an overlay created from a module",
|
||||
example: r#"module spam { export def foo [] { "foo" } }
|
||||
overlay add spam
|
||||
overlay remove spam"#,
|
||||
overlay use spam
|
||||
overlay hide spam"#,
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description: "Remove an overlay created from a file",
|
||||
description: "Hide an overlay created from a file",
|
||||
example: r#"echo 'export alias f = "foo"' | save spam.nu
|
||||
overlay add spam.nu
|
||||
overlay remove spam"#,
|
||||
overlay use spam.nu
|
||||
overlay hide spam"#,
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description: "Remove the last activated overlay",
|
||||
description: "Hide the last activated overlay",
|
||||
example: r#"module spam { export env FOO { "foo" } }
|
||||
overlay add spam
|
||||
overlay remove"#,
|
||||
overlay use spam
|
||||
overlay hide"#,
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description: "Keep the current working directory when removing an overlay",
|
||||
example: r#"overlay new spam
|
||||
cd some-dir
|
||||
overlay remove --keep-env [ PWD ] spam"#,
|
||||
overlay hide --keep-env [ PWD ] spam"#,
|
||||
result: None,
|
||||
},
|
||||
]
|
@ -74,7 +74,7 @@ impl Command for OverlayList {
|
||||
vec![Example {
|
||||
description: "Get the last activated overlay",
|
||||
example: r#"module spam { export def foo [] { "foo" } }
|
||||
overlay add spam
|
||||
overlay use spam
|
||||
overlay list | last"#,
|
||||
result: Some(Value::String {
|
||||
val: "spam".to_string(),
|
||||
|
@ -1,11 +1,11 @@
|
||||
mod add;
|
||||
mod command;
|
||||
mod hide;
|
||||
mod list;
|
||||
mod new;
|
||||
mod remove;
|
||||
mod use_;
|
||||
|
||||
pub use add::OverlayAdd;
|
||||
pub use command::Overlay;
|
||||
pub use hide::OverlayHide;
|
||||
pub use list::OverlayList;
|
||||
pub use new::OverlayNew;
|
||||
pub use remove::OverlayRemove;
|
||||
pub use use_::OverlayUse;
|
||||
|
@ -6,23 +6,23 @@ use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Spanne
|
||||
use std::path::Path;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct OverlayAdd;
|
||||
pub struct OverlayUse;
|
||||
|
||||
impl Command for OverlayAdd {
|
||||
impl Command for OverlayUse {
|
||||
fn name(&self) -> &str {
|
||||
"overlay add"
|
||||
"overlay use"
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
"Add definitions from a module as an overlay"
|
||||
"Use definitions from a module as an overlay"
|
||||
}
|
||||
|
||||
fn signature(&self) -> nu_protocol::Signature {
|
||||
Signature::build("overlay add")
|
||||
Signature::build("overlay use")
|
||||
.required(
|
||||
"name",
|
||||
SyntaxShape::String,
|
||||
"Module name to create overlay for",
|
||||
"Module name to use overlay for",
|
||||
)
|
||||
.optional(
|
||||
"as",
|
||||
@ -145,21 +145,21 @@ impl Command for OverlayAdd {
|
||||
Example {
|
||||
description: "Create an overlay from a module",
|
||||
example: r#"module spam { export def foo [] { "foo" } }
|
||||
overlay add spam
|
||||
overlay use spam
|
||||
foo"#,
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description: "Create an overlay with a prefix",
|
||||
example: r#"echo 'export def foo { "foo" }'
|
||||
overlay add --prefix spam
|
||||
overlay use --prefix spam
|
||||
spam foo"#,
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description: "Create an overlay from a file",
|
||||
example: r#"echo 'export env FOO { "foo" }' | save spam.nu
|
||||
overlay add spam.nu
|
||||
overlay use spam.nu
|
||||
$env.FOO"#,
|
||||
result: None,
|
||||
},
|
||||
@ -175,6 +175,6 @@ mod test {
|
||||
fn test_examples() {
|
||||
use crate::test_examples;
|
||||
|
||||
test_examples(OverlayAdd {})
|
||||
test_examples(OverlayUse {})
|
||||
}
|
||||
}
|
@ -51,10 +51,10 @@ pub fn create_default_context() -> EngineState {
|
||||
If,
|
||||
Ignore,
|
||||
Overlay,
|
||||
OverlayAdd,
|
||||
OverlayUse,
|
||||
OverlayList,
|
||||
OverlayNew,
|
||||
OverlayRemove,
|
||||
OverlayHide,
|
||||
Let,
|
||||
Metadata,
|
||||
Module,
|
||||
|
@ -735,7 +735,7 @@ fn parse_script_with_nested_scripts_success() {
|
||||
r#"
|
||||
source ../foo.nu
|
||||
use lol_shell.nu
|
||||
overlay add ../lol/lol_shell.nu
|
||||
overlay use ../lol/lol_shell.nu
|
||||
"#,
|
||||
)])
|
||||
.with_files(vec![FileWithContentToBeTrimmed(
|
||||
|
@ -152,13 +152,13 @@ pub enum ParseError {
|
||||
)]
|
||||
CantRemoveLastOverlay(#[label = "this is the last overlay, can't remove it"] Span),
|
||||
|
||||
#[error("Cannot remove default overlay.")]
|
||||
#[error("Cannot hide default overlay.")]
|
||||
#[diagnostic(
|
||||
code(nu::parser::cant_remove_default_overlay),
|
||||
code(nu::parser::cant_hide_default_overlay),
|
||||
url(docsrs),
|
||||
help("'{0}' is a default overlay. Default overlays cannot be removed.")
|
||||
help("'{0}' is a default overlay. Default overlays cannot be hidden.")
|
||||
)]
|
||||
CantRemoveDefaultOverlay(String, #[label = "can't remove overlay"] Span),
|
||||
CantHideDefaultOverlay(String, #[label = "can't hide overlay"] Span),
|
||||
|
||||
#[error("Cannot add overlay.")]
|
||||
#[diagnostic(code(nu::parser::cant_add_overlay_help), url(docsrs), help("{0}"))]
|
||||
@ -345,7 +345,7 @@ impl ParseError {
|
||||
ParseError::ActiveOverlayNotFound(s) => *s,
|
||||
ParseError::OverlayPrefixMismatch(_, _, s) => *s,
|
||||
ParseError::CantRemoveLastOverlay(s) => *s,
|
||||
ParseError::CantRemoveDefaultOverlay(_, s) => *s,
|
||||
ParseError::CantHideDefaultOverlay(_, s) => *s,
|
||||
ParseError::CantAddOverlayHelp(_, s) => *s,
|
||||
ParseError::NotFound(s) => *s,
|
||||
ParseError::DuplicateCommandDef(s) => *s,
|
||||
|
@ -1823,8 +1823,8 @@ pub fn parse_overlay(
|
||||
let subcommand = working_set.get_span_contents(spans[1]);
|
||||
|
||||
match subcommand {
|
||||
b"add" => {
|
||||
return parse_overlay_add(working_set, spans, expand_aliases_denylist);
|
||||
b"use" => {
|
||||
return parse_overlay_use(working_set, spans, expand_aliases_denylist);
|
||||
}
|
||||
b"list" => {
|
||||
// TODO: Abstract this code blob, it's repeated all over the place:
|
||||
@ -1884,8 +1884,8 @@ pub fn parse_overlay(
|
||||
b"new" => {
|
||||
return parse_overlay_new(working_set, spans, expand_aliases_denylist);
|
||||
}
|
||||
b"remove" => {
|
||||
return parse_overlay_remove(working_set, spans, expand_aliases_denylist);
|
||||
b"hide" => {
|
||||
return parse_overlay_hide(working_set, spans, expand_aliases_denylist);
|
||||
}
|
||||
_ => { /* continue parsing overlay */ }
|
||||
}
|
||||
@ -2045,23 +2045,23 @@ pub fn parse_overlay_new(
|
||||
(pipeline, None)
|
||||
}
|
||||
|
||||
pub fn parse_overlay_add(
|
||||
pub fn parse_overlay_use(
|
||||
working_set: &mut StateWorkingSet,
|
||||
spans: &[Span],
|
||||
expand_aliases_denylist: &[usize],
|
||||
) -> (Pipeline, Option<ParseError>) {
|
||||
if spans.len() > 1 && working_set.get_span_contents(span(&spans[0..2])) != b"overlay add" {
|
||||
if spans.len() > 1 && working_set.get_span_contents(span(&spans[0..2])) != b"overlay use" {
|
||||
return (
|
||||
garbage_pipeline(spans),
|
||||
Some(ParseError::UnknownState(
|
||||
"internal error: Wrong call name for 'overlay add' command".into(),
|
||||
"internal error: Wrong call name for 'overlay use' command".into(),
|
||||
span(spans),
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: Allow full import pattern as argument (requires custom naming of module/overlay)
|
||||
let (call, call_span) = match working_set.find_decl(b"overlay add", &Type::Any) {
|
||||
let (call, call_span) = match working_set.find_decl(b"overlay use", &Type::Any) {
|
||||
Some(decl_id) => {
|
||||
let ParsedInternalCall {
|
||||
call,
|
||||
@ -2097,7 +2097,7 @@ pub fn parse_overlay_add(
|
||||
return (
|
||||
garbage_pipeline(spans),
|
||||
Some(ParseError::UnknownState(
|
||||
"internal error: 'overlay add' declaration not found".into(),
|
||||
"internal error: 'overlay use' declaration not found".into(),
|
||||
span(spans),
|
||||
)),
|
||||
)
|
||||
@ -2321,22 +2321,22 @@ pub fn parse_overlay_add(
|
||||
(pipeline, error)
|
||||
}
|
||||
|
||||
pub fn parse_overlay_remove(
|
||||
pub fn parse_overlay_hide(
|
||||
working_set: &mut StateWorkingSet,
|
||||
spans: &[Span],
|
||||
expand_aliases_denylist: &[usize],
|
||||
) -> (Pipeline, Option<ParseError>) {
|
||||
if spans.len() > 1 && working_set.get_span_contents(span(&spans[0..2])) != b"overlay remove" {
|
||||
if spans.len() > 1 && working_set.get_span_contents(span(&spans[0..2])) != b"overlay hide" {
|
||||
return (
|
||||
garbage_pipeline(spans),
|
||||
Some(ParseError::UnknownState(
|
||||
"internal error: Wrong call name for 'overlay remove' command".into(),
|
||||
"internal error: Wrong call name for 'overlay hide' command".into(),
|
||||
span(spans),
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
let call = match working_set.find_decl(b"overlay remove", &Type::Any) {
|
||||
let call = match working_set.find_decl(b"overlay hide", &Type::Any) {
|
||||
Some(decl_id) => {
|
||||
let ParsedInternalCall {
|
||||
call,
|
||||
@ -2372,7 +2372,7 @@ pub fn parse_overlay_remove(
|
||||
return (
|
||||
garbage_pipeline(spans),
|
||||
Some(ParseError::UnknownState(
|
||||
"internal error: 'overlay remove' declaration not found".into(),
|
||||
"internal error: 'overlay hide' declaration not found".into(),
|
||||
span(spans),
|
||||
)),
|
||||
)
|
||||
@ -2410,7 +2410,7 @@ pub fn parse_overlay_remove(
|
||||
if overlay_name == DEFAULT_OVERLAY_NAME {
|
||||
return (
|
||||
pipeline,
|
||||
Some(ParseError::CantRemoveDefaultOverlay(
|
||||
Some(ParseError::CantHideDefaultOverlay(
|
||||
overlay_name,
|
||||
overlay_name_span,
|
||||
)),
|
||||
|
Reference in New Issue
Block a user