nushell/crates/nu-command/src
Wind 387328fe73
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
2024-02-28 23:05:35 +08:00
..
bytes adjust some commansd input_output type (#11436) 2024-01-15 16:58:26 +08:00
charting Remove Record::from_raw_cols_vals_unchecked (#11810) 2024-02-18 14:20:22 +02:00
conversions Glob: don't allow implicit casting between glob and string (#11992) 2024-02-28 23:05:35 +08:00
database open, rm, umv, cp, rm and du: Don't globs if inputs are variables or string interpolation (#11886) 2024-02-23 09:17:09 +08:00
date Remove some unnecessary static Vecs (#11947) 2024-02-24 20:58:01 +01:00
debug open, rm, umv, cp, rm and du: Don't globs if inputs are variables or string interpolation (#11886) 2024-02-23 09:17:09 +08:00
env Add ConfigDirNotFound error (#11849) 2024-02-26 15:42:20 +08:00
experimental Bump windows from 0.48.0 to 0.52.0 (#11325) 2023-12-21 18:49:15 +01:00
filesystem Glob: don't allow implicit casting between glob and string (#11992) 2024-02-28 23:05:35 +08:00
filters Add upsert example (#12001) 2024-02-27 17:54:29 -06:00
formats Add date support in from xlsx (#11952) 2024-02-24 07:25:51 -06:00
generators allow current day to be highlighted (#11954) 2024-02-26 08:31:46 -06:00
hash adjust some commansd input_output type (#11436) 2024-01-15 16:58:26 +08:00
help adjust some commansd input_output type (#11436) 2024-01-15 16:58:26 +08:00
math allow math avg to work with durations (#11598) 2024-01-21 08:41:23 -06:00
misc wrapping run_repl with catch_unwind and restarting the repl on panic (#11860) 2024-02-22 12:14:10 -06:00
network Add Value::coerce_str (#11885) 2024-02-18 17:47:10 +01:00
path Add Value::coerce_str (#11885) 2024-02-18 17:47:10 +01:00
platform Allow clear command to clear terminal's history (#12008) 2024-02-28 07:49:41 -06:00
random Name the Value conversion functions more clearly (#11851) 2024-02-17 18:14:16 +00:00
removed Enforce required, optional, and rest positional arguments start with an uppercase and end with a period. (#11285) 2023-12-15 14:32:37 +08:00
shells Enforce required, optional, and rest positional arguments start with an uppercase and end with a period. (#11285) 2023-12-15 14:32:37 +08:00
stor Add Value::coerce_str (#11885) 2024-02-18 17:47:10 +01:00
strings Remove some unnecessary static Vecs (#11947) 2024-02-24 20:58:01 +01:00
system Don't expanding globs if user pass variables. (#11946) 2024-02-28 23:05:09 +08:00
viewers nu-table: Improve table -a (#11905) 2024-02-23 19:12:10 -06:00
default_context.rs Making coreutils umkdir as the default mkdir (#12007) 2024-02-28 06:27:10 -06:00
example_test.rs Add upsert example (#12001) 2024-02-27 17:54:29 -06:00
lib.rs Simplify the feature gates for stor commands (#11416) 2023-12-24 13:31:46 +01:00
progress_bar.rs remove cp-old (#11622) 2024-01-24 07:38:15 +08:00
sort_utils.rs Add Value::coerce_str (#11885) 2024-02-18 17:47:10 +01:00