nushell/crates/nu-command/src/filesystem
Antoine Stevan 7ac5a01e2f
deprecate glob --not in favor of glob --exclude (#10827)
# Description
looking at the [Wax documentation about
`wax::Walk.not`](https://docs.rs/wax/latest/wax/struct.Walk.html#examples),
especially
> therefore does not read directory trees from the file system when a
directory matches an [exhaustive glob
expression](https://docs.rs/wax/latest/wax/trait.Pattern.html#tymethod.is_exhaustive)

> **Important**
> in the following of this PR description, i talk about *pruning* and a
`--prune` option, but this has been changed to *exclusion* and
`--exclude` after a discussion with @fdncred.

this looks like a *pruning* operation to me, right? 😮 
i wanted to make the `glob` option `--not` clearer about that, because
>   -n, --not <List(String)> - Patterns to exclude from the results

from `help glob` is not very explicit about whether the search is pruned
when entering a directory matching a pattern in `--not` or just removing
it from the output 😕

## changelog
this PR proposes to rename the `glob --not` option to `glob --prune` and
make it's documentation more explicit 😋

## benchmarking
to support the *pruning* behaviour put forward above, i've run a
benchmark
1. define two closures to compare the behaviour between removing
patterns manually or using `--not`
```nushell
let where = {
    [.*/\.local/.*, .*/documents/.*, .*/\.config/.*]
        | reduce --fold (glob **) {|pat, acc| $acc | where $it !~ $pat}
        | length
}
```
```nushell
let not = { glob ** --not [**/.local/**, **/documents/**, **/.config/**] | length }
```
2. run the two to make sure they give similar results
```nushell
> do $where
33424
```
```nushell
> do $not
33420
```
👌 
3. measure the performance
```nushell
use std bench
```
```nushell
> bench --verbose --pretty --rounds 25 $not
44ms 52µs 285ns +/- 977µs 571ns
```
```nushell
> bench --verbose --pretty --rounds 5 $where
1sec 250ms 187µs 99ns +/- 8ms 538µs 57ns
```

👉 we can see that the results are (almost) the same but
`--not` is much faster, looks like pruning 😋

# User-Facing Changes
- `--not` will give a warning message but still work
- `--prune` will work just as `--not` without warning and with a more
explicit doc
- `--prune` and `--not` at the same time will give an error

# Tests + Formatting
this PR fixes the examples of `glob` using the `--not` option.

# After Submitting
prepare the removal PR and mention in release notes.
2023-10-25 17:11:57 +02:00
..
cd.rs Remove cd w/ abbreviations (#10588) 2023-10-03 10:51:46 +13:00
cp.rs Allow filesystem commands to access files with glob metachars in name (#10694) 2023-10-18 13:31:15 -05:00
glob.rs deprecate glob --not in favor of glob --exclude (#10827) 2023-10-25 17:11:57 +02:00
ls.rs Finish removing profile command and related data (#10807) 2023-10-22 14:06:53 +03:00
mkdir.rs Move Value to helpers, separate span call (#10121) 2023-09-03 07:27:29 -07:00
mod.rs Remove cd w/ abbreviations (#10588) 2023-10-03 10:51:46 +13:00
mv.rs Allow filesystem commands to access files with glob metachars in name (#10694) 2023-10-18 13:31:15 -05:00
open.rs allow multiple extensions (#10593) 2023-10-13 13:45:36 -05:00
rm.rs Allow filesystem commands to access files with glob metachars in name (#10694) 2023-10-18 13:31:15 -05:00
save.rs Invert &Options to Option<&T> (#10315) 2023-09-13 07:00:58 +08:00
start.rs fix clippy (#10659) 2023-10-10 03:31:15 +13:00
touch.rs Document and critically review ShellError variants - Ep. 2 (#8326) 2023-03-06 11:31:07 +01:00
ucp.rs readd update flag to cp command (#10824) 2023-10-25 11:30:13 +02:00
util.rs Fix cp -u/mv -u when the dst doesn't exist (#9662) 2023-07-12 18:12:59 +02:00
watch.rs show the full directory / file path in "directory not found" error (#10430) 2023-09-26 17:38:58 +08:00