fix du --exclude globbing bug (#12093)

# Description

This PR fixes a globbing bug in the `du` command. The problem was that
`--exclude` needed to be a `NuGlob` instead of a `String`. A variety of
ways were tried to fix this, including spread operators and `into glob`
but none of them worked. Here's the [Discord
Conversation](https://discord.com/channels/601130461678272522/1214950311207243796/1214950311207243796)
that documents the attempts.

### Before
```nushell
❯ du $env.PWD -x crates/**
Error: nu:🐚:cant_convert

  × Can't convert to string.
   ╭─[entry #1:1:16]
 1 │ du $env.PWD -x crates/**
   ·                ────┬────
   ·                    ╰── can't convert glob to string
   ╰────
```
### After
```nushell
❯ du $env.PWD -x crates/**
╭─#─┬────path────┬apparent─┬physical─┬───directories───┬files╮
│ 0 │ D:\nushell │ 55.6 MB │ 55.6 MB │ [table 17 rows] │     │
╰───┴────────────┴─────────┴─────────┴─────────────────┴─────╯
```
This commit is contained in:
Darren Schroeder 2024-03-06 16:15:53 -06:00 committed by GitHub
parent fe2761c7a6
commit 2ee3538de4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -18,7 +18,7 @@ pub struct DuArgs {
path: Option<Spanned<NuGlob>>,
all: bool,
deref: bool,
exclude: Option<Spanned<String>>,
exclude: Option<Spanned<NuGlob>>,
#[serde(rename = "max-depth")]
max_depth: Option<Spanned<i64>>,
#[serde(rename = "min-size")]
@ -110,7 +110,7 @@ impl Command for Du {
};
let exclude = args.exclude.map_or(Ok(None), move |x| {
Pattern::new(&x.item)
Pattern::new(x.item.as_ref())
.map(Some)
.map_err(|e| ShellError::InvalidGlobPattern {
msg: e.msg.into(),