forked from extern/nushell
Glob: don't allow implicit casting between glob and string (#11992)
# Description As title, currently on latest main, nushell confused user if it allows implicit casting between glob and string: ```nushell let x = "*.txt" def glob-test [g: glob] { open $g } glob-test $x ``` It always expand the glob although `$x` is defined as a string. This pr implements a solution from @kubouch : > We could make it really strict and disallow all autocasting between globs and strings because that's what's causing the "magic" confusion. Then, modify all builtins that accept globs to accept oneof(glob, string) and the rules would be that globs always expand and strings never expand # User-Facing Changes After this pr, user needs to use `into glob` to invoke `glob-test`, if user pass a string variable: ```nushell let x = "*.txt" def glob-test [g: glob] { open $g } glob-test ($x | into glob) ``` Or else nushell will return an error. ``` 3 │ glob-test $x · ─┬ · ╰── can't convert string to glob ``` # Tests + Formatting Done # After Submitting Nan
This commit is contained in:
@ -68,10 +68,10 @@ impl Command for SubCommand {
|
||||
Example {
|
||||
description: "convert string to glob",
|
||||
example: "'1234' | into glob",
|
||||
result: Some(Value::test_string("1234")),
|
||||
result: Some(Value::test_glob("1234")),
|
||||
},
|
||||
Example {
|
||||
description: "convert filepath to string",
|
||||
description: "convert filepath to glob",
|
||||
example: "ls Cargo.toml | get name | into glob",
|
||||
result: None,
|
||||
},
|
||||
|
@ -38,7 +38,11 @@ impl Command for Du {
|
||||
Signature::build("du")
|
||||
.input_output_types(vec![(Type::Nothing, Type::Table(vec![]))])
|
||||
.allow_variants_without_examples(true)
|
||||
.optional("path", SyntaxShape::GlobPattern, "Starting directory.")
|
||||
.optional(
|
||||
"path",
|
||||
SyntaxShape::OneOf(vec![SyntaxShape::GlobPattern, SyntaxShape::String]),
|
||||
"Starting directory.",
|
||||
)
|
||||
.switch(
|
||||
"all",
|
||||
"Output file sizes as well as directory sizes",
|
||||
|
@ -42,7 +42,7 @@ impl Command for Ls {
|
||||
.input_output_types(vec![(Type::Nothing, Type::Table(vec![]))])
|
||||
// LsGlobPattern is similar to string, it won't auto-expand
|
||||
// and we use it to track if the user input is quoted.
|
||||
.optional("pattern", SyntaxShape::GlobPattern, "The glob pattern to use.")
|
||||
.optional("pattern", SyntaxShape::OneOf(vec![SyntaxShape::GlobPattern, SyntaxShape::String]), "The glob pattern to use.")
|
||||
.switch("all", "Show hidden files", Some('a'))
|
||||
.switch(
|
||||
"long",
|
||||
|
@ -43,7 +43,11 @@ impl Command for Open {
|
||||
fn signature(&self) -> nu_protocol::Signature {
|
||||
Signature::build("open")
|
||||
.input_output_types(vec![(Type::Nothing, Type::Any), (Type::String, Type::Any)])
|
||||
.rest("files", SyntaxShape::GlobPattern, "The file(s) to open.")
|
||||
.rest(
|
||||
"files",
|
||||
SyntaxShape::OneOf(vec![SyntaxShape::GlobPattern, SyntaxShape::String]),
|
||||
"The file(s) to open.",
|
||||
)
|
||||
.switch("raw", "open file as raw binary", Some('r'))
|
||||
.category(Category::FileSystem)
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ impl Command for Rm {
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("rm")
|
||||
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
|
||||
.rest("paths", SyntaxShape::GlobPattern, "The file paths(s) to remove.")
|
||||
.rest("paths", SyntaxShape::OneOf(vec![SyntaxShape::GlobPattern, SyntaxShape::String]), "The file paths(s) to remove.")
|
||||
.switch(
|
||||
"trash",
|
||||
"move to the platform's trash instead of permanently deleting. not used on android and ios",
|
||||
|
@ -61,7 +61,7 @@ impl Command for UCp {
|
||||
None
|
||||
)
|
||||
.switch("debug", "explain how a file is copied. Implies -v", None)
|
||||
.rest("paths", SyntaxShape::GlobPattern, "Copy SRC file/s to DEST.")
|
||||
.rest("paths", SyntaxShape::OneOf(vec![SyntaxShape::GlobPattern, SyntaxShape::String]), "Copy SRC file/s to DEST.")
|
||||
.allow_variants_without_examples(true)
|
||||
.category(Category::FileSystem)
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ impl Command for UMv {
|
||||
.switch("no-clobber", "do not overwrite an existing file", Some('n'))
|
||||
.rest(
|
||||
"paths",
|
||||
SyntaxShape::GlobPattern,
|
||||
SyntaxShape::OneOf(vec![SyntaxShape::GlobPattern, SyntaxShape::String]),
|
||||
"Rename SRC to DST, or move SRC to DIR.",
|
||||
)
|
||||
.allow_variants_without_examples(true)
|
||||
|
Reference in New Issue
Block a user