Rename/deprecate range to slice (#14825)

# Description
As the `range` command has an ambiguous name (does it construct a range
type?, does it iterate a range like `seq`) replace it with a more
descriptive verb of what it does: `slice`

Closes #14130
# User-Facing Changes
`range` is now deprecated and replaced in whole by `slice` with the same
behavior.
`range` will be removed in `0.103.0`

# Tests + Formatting
Tests have been updated to use `slice`

# After submitting

- [ ] prepare PR for `nu_scripts` (several usages of `range` to be
fixed)
- [ ] update documentation usages of `range` after release
This commit is contained in:
Stefan Holderbach
2025-01-17 13:21:32 +01:00
committed by GitHub
parent 089c5221cc
commit 4dcaf2a201
7 changed files with 167 additions and 74 deletions

View File

@ -82,7 +82,6 @@ mod print;
#[cfg(feature = "sqlite")]
mod query;
mod random;
mod range;
mod redirection;
mod reduce;
mod reject;
@ -100,6 +99,7 @@ mod seq;
mod seq_char;
mod seq_date;
mod skip;
mod slice;
mod sort;
mod sort_by;
mod source_env;

View File

@ -4,7 +4,7 @@ use nu_test_support::{nu, pipeline};
#[test]
fn selects_a_row() {
Playground::setup("range_test_1", |dirs, sandbox| {
Playground::setup("slice_test_1", |dirs, sandbox| {
sandbox.with_files(&[EmptyFile("notes.txt"), EmptyFile("tests.txt")]);
let actual = nu!(
@ -12,7 +12,7 @@ fn selects_a_row() {
"
ls
| sort-by name
| range 0..0
| slice 0..0
| get name.0
"
));
@ -23,7 +23,7 @@ fn selects_a_row() {
#[test]
fn selects_some_rows() {
Playground::setup("range_test_2", |dirs, sandbox| {
Playground::setup("slice_test_2", |dirs, sandbox| {
sandbox.with_files(&[
EmptyFile("notes.txt"),
EmptyFile("tests.txt"),
@ -35,7 +35,7 @@ fn selects_some_rows() {
"
ls
| get name
| range 1..2
| slice 1..2
| length
"
));
@ -46,7 +46,7 @@ fn selects_some_rows() {
#[test]
fn negative_indices() {
Playground::setup("range_test_negative_indices", |dirs, sandbox| {
Playground::setup("slice_test_negative_indices", |dirs, sandbox| {
sandbox.with_files(&[
EmptyFile("notes.txt"),
EmptyFile("tests.txt"),
@ -58,7 +58,7 @@ fn negative_indices() {
"
ls
| get name
| range (-1..)
| slice (-1..)
| length
"
));