nushell/crates/nu-command/src/strings
Reilly Wood 2aa5c2c41f
Simplify str trim command (#8205)
### What?

This change removes 3 flags (`--all`, `--both`, and `--format`) from
`str trim`. This is a net reduction of ~450 LoC and `str trim` no longer
depends on `fancy_regex`.

### Why?

I found these flags to be quite confusing when reviewing `str trim`
earlier today:

1. `--all` removes characters even if they're in the centre of the the
string.
- This is arguably not "trimming"! In all programming languages I'm
familiar with, trimming only affects the start and end of a string.
    - If someone needs to do this, `str replace` is more natural IMO
2. `--both` trims from the left and right
- Confusing and unnecessary given that this is also the default
behaviour
3. `--format` replaces multiple spaces with a single space, even in the
centre of the string
- Again, I don't think this falls under the scope of "trimming". IMO
`str replace` is a more natural fit

I believe that `str trim` is simpler and easier to understand after this
change.

### Before

```
〉help str trim
Trim whitespace or specific character

Search terms: whitespace, strip, lstrip, rstrip

Usage:
  > str trim {flags} ...(rest)

Flags:
  -h, --help - Display the help message for this command
  -c, --char <String> - character to trim (default: whitespace)
  -l, --left - trims characters only from the beginning of the string
  -r, --right - trims characters only from the end of the string
  -a, --all - trims all characters from both sides of the string *and* in the middle
  -b, --both - trims all characters from left and right side of the string
  -f, --format - trims spaces replacing multiple characters with singles in the middle
```

### After

```
〉help str trim
Trim whitespace or specific character

Search terms: whitespace, strip, lstrip, rstrip

Usage:
  > str trim {flags} ...(rest)

Flags:
  -h, --help - Display the help message for this command
  -c, --char <String> - character to trim (default: whitespace)
  -l, --left - trims characters only from the beginning of the string
  -r, --right - trims characters only from the end of the string
```
2023-02-26 12:23:30 -08:00
..
encode_decode Use variable names directly in the format strings (#7906) 2023-01-29 19:37:54 -06:00
format Use variable names directly in the format strings (#7906) 2023-01-29 19:37:54 -06:00
split Use imported names in Command::run signatures (#7967) 2023-02-05 22:17:46 +01:00
str_ Simplify str trim command (#8205) 2023-02-26 12:23:30 -08:00
char_.rs Use imported names in Command::run signatures (#7967) 2023-02-05 22:17:46 +01:00
detect_columns.rs Remove unnecessary echo uses from examples (#7500) 2022-12-16 11:51:00 -05:00
mod.rs Add Github Actions workflow to check for typos (#7892) 2023-01-29 10:22:56 +13:00
parse.rs allow parse to work better with streams (#7870) 2023-02-08 20:59:02 -06:00
size.rs Use variable names directly in the format strings (#7906) 2023-01-29 19:37:54 -06:00