toolkit: use --features instead of --dataframe and refactor a bit (#9425)

related to
- https://github.com/nushell/nushell/pull/9357

# Description
with the new `extra` feature introduce in the `toolkit.nu` module in
https://github.com/nushell/nushell/pull/9357, the `--dataframe` option
does not make sense anymore...

this PR changes that and replaces it with `--features: list<string>`.
this has the benefit of simplifying the commands because we can just
pass `--features ($features | str join ",")` to the `cargo` commands
regardless of whether the `$features` list is empty of not 👌

i've also refactored a bit the module:
- break the long `error make -u` lines
- break the long `cargo clippy` command

# User-Facing Changes
devs can now choose which feature to test with the `toolkit` commands.

# Tests + Formatting
- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
-  `toolkit test`
-  `toolkit test stdlib`

# After Submitting
```
$nothing
```
This commit is contained in:
Antoine Stevan 2023-06-18 16:16:05 +02:00 committed by GitHub
parent fa957a1a07
commit 6af9fe5e10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,7 +19,9 @@ export def fmt [
try { try {
cargo fmt --all -- --check cargo fmt --all -- --check
} catch { } catch {
error make -u { msg: $"\nplease run ('toolkit fmt' | pretty-print-command) to fix formatting!" } error make --unspanned {
msg: $"\nplease run ('toolkit fmt' | pretty-print-command) to fix formatting!"
}
} }
} else { } else {
cargo fmt --all cargo fmt --all
@ -31,36 +33,56 @@ export def fmt [
# > it is important to make `clippy` happy :relieved: # > it is important to make `clippy` happy :relieved:
export def clippy [ export def clippy [
--verbose: bool # print extra information about the command's progress --verbose: bool # print extra information about the command's progress
--dataframe: bool # use the dataframe feature --features: list<string> # the list of features to run *Clippy* on
--workspace: bool # run the *Clippy* command on the whole workspace (overrides `--features`)
] { ] {
if $verbose { if $verbose {
print $"running ('toolkit clippy' | pretty-print-command)" print $"running ('toolkit clippy' | pretty-print-command)"
} }
try { try {
if $dataframe { if $workspace {(
cargo clippy --workspace --features=dataframe,extra -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err cargo clippy
} else { --workspace
cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err --
} -D warnings
-D clippy::unwrap_used
-A clippy::needless_collect
-A clippy::result_large_err
)} else {(
cargo clippy
--features ($features | str join ",")
--
-D warnings
-D clippy::unwrap_used
-A clippy::needless_collect
-A clippy::result_large_err
)}
} catch { } catch {
error make -u { msg: $"\nplease fix the above ('clippy' | pretty-print-command) errors before continuing!" } error make --unspanned {
msg: $"\nplease fix the above ('clippy' | pretty-print-command) errors before continuing!"
}
} }
} }
# check that all the tests pass # check that all the tests pass
export def test [ export def test [
--fast: bool # use the "nextext" `cargo` subcommand to speed up the tests (see [`cargo-nextest`](https://nexte.st/) and [`nextest-rs/nextest`](https://github.com/nextest-rs/nextest)) --fast: bool # use the "nextext" `cargo` subcommand to speed up the tests (see [`cargo-nextest`](https://nexte.st/) and [`nextest-rs/nextest`](https://github.com/nextest-rs/nextest))
--dataframe: bool # use the dataframe feature --features: list<string> # the list of features to run the tests on
--workspace: bool # run the *Clippy* command on the whole workspace (overrides `--features`)
] { ] {
if ($fast and $dataframe) { if $fast {
cargo nextest run --all --features=dataframe,extra if $workspace {
} else if ($fast) {
cargo nextest run --all cargo nextest run --all
} else if ($dataframe) {
cargo test --workspace --features=dataframe,extra
} else { } else {
cargo nextest run --features ($features | str join ",")
}
} else {
if $workspace {
cargo test --workspace cargo test --workspace
} else {
cargo test --features ($features | str join ",")
}
} }
} }
@ -208,7 +230,7 @@ def report [
# now the whole `toolkit check pr` passes! :tada: # now the whole `toolkit check pr` passes! :tada:
export def "check pr" [ export def "check pr" [
--fast: bool # use the "nextext" `cargo` subcommand to speed up the tests (see [`cargo-nextest`](https://nexte.st/) and [`nextest-rs/nextest`](https://github.com/nextest-rs/nextest)) --fast: bool # use the "nextext" `cargo` subcommand to speed up the tests (see [`cargo-nextest`](https://nexte.st/) and [`nextest-rs/nextest`](https://github.com/nextest-rs/nextest))
--dataframe: bool # use the dataframe feature --features: list<string> # the list of features to check the current PR on
] { ] {
let-env NU_TEST_LOCALE_OVERRIDE = 'en_US.utf8'; let-env NU_TEST_LOCALE_OVERRIDE = 'en_US.utf8';
try { try {
@ -218,23 +240,17 @@ export def "check pr" [
} }
try { try {
if $dataframe { clippy --features $features --verbose
clippy --dataframe --verbose
} else {
clippy --verbose
}
} catch { } catch {
return (report --fail-clippy) return (report --fail-clippy)
} }
print $"running ('toolkit test' | pretty-print-command)" print $"running ('toolkit test' | pretty-print-command)"
try { try {
if $fast and $dataframe { if $fast {
test --fast --dataframe test --features $features --fast
} else if $fast {
test --fast
} else { } else {
test test --features $features
} }
} catch { } catch {
return (report --fail-test) return (report --fail-test)