2022-03-17 23:35:50 +01:00
|
|
|
mod alias;
|
2021-04-03 20:40:54 +02:00
|
|
|
mod all;
|
|
|
|
mod any;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod append;
|
2022-12-09 17:20:58 +01:00
|
|
|
mod assignment;
|
New commands: `break`, `continue`, `return`, and `loop` (#7230)
# Description
This adds `break`, `continue`, `return`, and `loop`.
* `break` - breaks out a loop
* `continue` - continues a loop at the next iteration
* `return` - early return from a function call
* `loop` - loop forever (until the loop hits a break)
Examples:
```
for i in 1..10 {
if $i == 5 {
continue
}
print $i
}
```
```
for i in 1..10 {
if $i == 5 {
break
}
print $i
}
```
```
def foo [x] {
if true {
return 2
}
$x
}
foo 100
```
```
loop { print "hello, forever" }
```
```
[1, 2, 3, 4, 5] | each {|x|
if $x > 3 { break }
$x
}
```
# User-Facing Changes
Adds the above commands.
# Tests + Formatting
Don't forget to add tests that cover your changes.
Make sure you've run and fixed any issues with these commands:
- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass
# After Submitting
If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2022-11-24 21:39:16 +01:00
|
|
|
mod break_;
|
2020-05-10 01:05:48 +02:00
|
|
|
mod cal;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod cd;
|
|
|
|
mod compact;
|
2023-09-25 15:00:59 +02:00
|
|
|
mod config_env_default;
|
|
|
|
mod config_nu_default;
|
New commands: `break`, `continue`, `return`, and `loop` (#7230)
# Description
This adds `break`, `continue`, `return`, and `loop`.
* `break` - breaks out a loop
* `continue` - continues a loop at the next iteration
* `return` - early return from a function call
* `loop` - loop forever (until the loop hits a break)
Examples:
```
for i in 1..10 {
if $i == 5 {
continue
}
print $i
}
```
```
for i in 1..10 {
if $i == 5 {
break
}
print $i
}
```
```
def foo [x] {
if true {
return 2
}
$x
}
foo 100
```
```
loop { print "hello, forever" }
```
```
[1, 2, 3, 4, 5] | each {|x|
if $x > 3 { break }
$x
}
```
# User-Facing Changes
Adds the above commands.
# Tests + Formatting
Don't forget to add tests that cover your changes.
Make sure you've run and fixed any issues with these commands:
- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass
# After Submitting
If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2022-11-24 21:39:16 +01:00
|
|
|
mod continue_;
|
2023-08-24 14:08:58 +02:00
|
|
|
mod conversions;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod cp;
|
2022-05-23 18:59:34 +02:00
|
|
|
mod date;
|
2023-10-24 19:48:05 +02:00
|
|
|
mod debug_info;
|
2021-01-07 18:14:51 +01:00
|
|
|
mod def;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod default;
|
2023-07-21 15:25:06 +02:00
|
|
|
mod detect_columns;
|
2022-06-30 03:01:34 +02:00
|
|
|
mod do_;
|
2020-04-26 08:34:45 +02:00
|
|
|
mod drop;
|
2020-04-13 09:59:57 +02:00
|
|
|
mod each;
|
2020-07-06 10:23:27 +02:00
|
|
|
mod echo;
|
2020-10-06 12:21:20 +02:00
|
|
|
mod empty;
|
2022-07-12 13:03:50 +02:00
|
|
|
mod error_make;
|
2020-06-16 21:58:41 +02:00
|
|
|
mod every;
|
2022-12-21 23:33:26 +01:00
|
|
|
mod exec;
|
2022-08-02 17:26:16 +02:00
|
|
|
mod export_def;
|
`string | fill` counts clusters, not graphemes; and doesn't count ANSI escape codes (#8134)
Enhancement of new `fill` command (#7846) to handle content including
ANSI escape codes for formatting or multi-code-point Unicode grapheme
clusters.
In both of these cases, the content is (many) bytes longer than its
visible length, and `fill` was counting the extra bytes so not adding
enough fill characters.
# Description
This script:
```rust
# the teacher emoji `\u{1F9D1}\u{200D}\u{1F3EB}` is 3 code points, but only 1 print position wide.
echo "This output should be 3 print positions wide, with leading and trailing `+`"
$"\u{1F9D1}\u{200D}\u{1F3EB}" | fill -c "+" -w 3 -a "c"
echo "This output should be 3 print positions wide, with leading and trailing `+`"
$"(ansi green)a(ansi reset)" | fill -c "+" -w 3 -a c
echo ""
```
Was producing this output:
```rust
This output should be 3 print positions wide, with leading and trailing `+`
🧑🏫
This output should be 3 print positions wide, with leading and trailing `+`
a
```
After this PR, it produces this output:
```rust
This output should be 3 print positions wide, with leading and trailing `+`
+🧑🏫+
This output should be 3 print positions wide, with leading and trailing `+`
+a+
```
# User-Facing Changes
Users may have to undo fixes they may have introduced to work around the
former behavior. I have one such in my prompt string that I can now
revert.
# Tests + Formatting
Don't forget to add tests that cover your changes.
-- Done
Make sure you've run and fixed any issues with these commands:
- [x] `cargo fmt --all -- --check` to check standard code formatting
(`cargo fmt --all` applies these changes)
- [x] `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect` to check that you're using the standard code
style
- [x] `cargo test --workspace` to check that all tests pass
# After Submitting
`fill` command not documented in the book, and it still talks about `str
lpad/rpad`. I'll fix.
Note added dependency on a new library `print-positions`, which is an
iterator that yields a complete print position (cluster + Ansi sequence)
per call. Should this be vendored?
2023-02-20 13:32:20 +01:00
|
|
|
mod fill;
|
2021-08-27 10:48:41 +02:00
|
|
|
mod find;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod first;
|
2020-10-14 11:36:11 +02:00
|
|
|
mod flatten;
|
2022-12-11 17:46:03 +01:00
|
|
|
mod for_;
|
2023-07-06 17:31:31 +02:00
|
|
|
#[cfg(feature = "extra")]
|
2019-12-15 17:15:06 +01:00
|
|
|
mod format;
|
2023-10-19 16:30:34 +02:00
|
|
|
mod generate;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod get;
|
2022-10-15 18:00:38 +02:00
|
|
|
mod glob;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod group_by;
|
2020-11-30 18:47:35 +01:00
|
|
|
mod hash_;
|
2020-03-29 04:05:57 +02:00
|
|
|
mod headers;
|
2021-02-26 21:05:22 +01:00
|
|
|
mod help;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod histogram;
|
2022-03-17 18:55:02 +01:00
|
|
|
mod insert;
|
2023-05-22 20:54:04 +02:00
|
|
|
mod inspect;
|
2023-07-23 20:14:51 +02:00
|
|
|
mod into_datetime;
|
2021-09-03 01:19:54 +02:00
|
|
|
mod into_filesize;
|
2020-08-27 07:44:18 +02:00
|
|
|
mod into_int;
|
2023-03-17 00:57:20 +01:00
|
|
|
mod join;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod last;
|
2021-03-13 22:46:40 +01:00
|
|
|
mod length;
|
2022-06-24 23:55:25 +02:00
|
|
|
mod let_;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod lines;
|
2022-12-11 17:46:03 +01:00
|
|
|
mod loop_;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod ls;
|
2023-03-27 00:31:57 +02:00
|
|
|
mod match_;
|
2020-04-18 03:50:58 +02:00
|
|
|
mod math;
|
2020-04-30 06:18:24 +02:00
|
|
|
mod merge;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod mkdir;
|
Add `mktemp` command (#11005)
closes #10845
I've opened this a little prematurely to get some questions answered
before I cleanup the code.
As I started trying to better understand GNUs `mktemp` I've realized its
kind of peculiar and we might want to change its behavior to introduce
it to nushell.
#### quiet and dry run
Does it make sense to keep the `quiet` and `dry_run` flags? I don't
think so. The GNU documentation says this about the dry run flag "Using
the output of this command to create a new file is inherently unsafe, as
there is a window of time between generating the name and using it where
another process can create an object by the same name." So yeah why keep
it? As far as quiet goes, does it make sense to silence the errors in
nushell?
#### other confusing flags
According to the [gnu
docs](https://www.gnu.org/software/coreutils/manual/html_node/mktemp-invocation.html),
the `-t` flag is deprecated and the `-p`/ `--tempdir` are the same flag
with the only difference being `--tempdir` takes an optional path, Given
that, I've broken the `-p` away from `--tempdir`. Now there is one
switch `--tmpdir`/`-t` and one named param `--tmpdir-path`/`-p`.
GNU mktemp
```
-p DIR, --tmpdir[=DIR] interpret TEMPLATE relative to DIR; if DIR is not
specified, use $TMPDIR if set, else /tmp. With
this option, TEMPLATE must not be an absolute name;
unlike with -t, TEMPLATE may contain slashes, but
mktemp creates only the final component
-t interpret TEMPLATE as a single file name component,
relative to a directory: $TMPDIR, if set; else the
directory specified via -p; else /tmp [deprecated]
```
to
nushell mktemp
```
-p, --tmpdir-path <Filepath> # named param, must provide a path
-t, --tmpdir # a switch
```
Is this a terrible idea?
What should I do?
---------
Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
2023-11-18 02:30:53 +01:00
|
|
|
mod mktemp;
|
2020-07-06 17:27:01 +02:00
|
|
|
mod move_;
|
2022-11-11 07:51:08 +01:00
|
|
|
mod mut_;
|
2022-06-22 05:27:58 +02:00
|
|
|
mod network;
|
2022-06-26 13:53:06 +02:00
|
|
|
mod nu_check;
|
2022-02-04 03:01:45 +01:00
|
|
|
mod open;
|
Fix unexpected flattening of data by par-each (Issue #8497) (#9007)
# Description
Previously, `par-each` acted like a `flatmap`: first mapping the data,
then applying a `flatten`. This is unlike `each`, which just maps the
data. Now `par-each` works like `each` in this regard, leaving nested
data unflattened.
Fixes #8497
# User-Facing Changes
Previously:
`[1 2 3] | par-each {|e| [$e, $e] }` --> `[1,1,2,2,3,3]`
Now:
`[1 2 3] | par-each {|e| [$e, $e] }` --> `[[1,1],[2,2],[3,3]]`
# Tests
This adds one test that verifies the lack of flattening for `par-each`.
2023-04-26 23:27:27 +02:00
|
|
|
mod par_each;
|
2022-02-04 03:01:45 +01:00
|
|
|
mod parse;
|
|
|
|
mod path;
|
2022-08-18 18:58:51 +02:00
|
|
|
mod platform;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod prepend;
|
2022-07-02 16:54:49 +02:00
|
|
|
mod print;
|
2022-11-23 01:58:11 +01:00
|
|
|
#[cfg(feature = "sqlite")]
|
2022-04-20 06:58:21 +02:00
|
|
|
mod query;
|
2020-06-25 07:51:09 +02:00
|
|
|
mod random;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod range;
|
2022-11-22 19:26:13 +01:00
|
|
|
mod redirection;
|
2020-08-04 19:16:19 +02:00
|
|
|
mod reduce;
|
2022-02-08 21:57:46 +01:00
|
|
|
mod reject;
|
2020-03-03 22:01:24 +01:00
|
|
|
mod rename;
|
New commands: `break`, `continue`, `return`, and `loop` (#7230)
# Description
This adds `break`, `continue`, `return`, and `loop`.
* `break` - breaks out a loop
* `continue` - continues a loop at the next iteration
* `return` - early return from a function call
* `loop` - loop forever (until the loop hits a break)
Examples:
```
for i in 1..10 {
if $i == 5 {
continue
}
print $i
}
```
```
for i in 1..10 {
if $i == 5 {
break
}
print $i
}
```
```
def foo [x] {
if true {
return 2
}
$x
}
foo 100
```
```
loop { print "hello, forever" }
```
```
[1, 2, 3, 4, 5] | each {|x|
if $x > 3 { break }
$x
}
```
# User-Facing Changes
Adds the above commands.
# Tests + Formatting
Don't forget to add tests that cover your changes.
Make sure you've run and fixed any issues with these commands:
- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass
# After Submitting
If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2022-11-24 21:39:16 +01:00
|
|
|
mod return_;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod reverse;
|
|
|
|
mod rm;
|
2023-07-06 17:31:31 +02:00
|
|
|
#[cfg(feature = "extra")]
|
2021-02-23 19:29:07 +01:00
|
|
|
mod roll;
|
2023-07-06 17:31:31 +02:00
|
|
|
#[cfg(feature = "extra")]
|
90 degree table rotations (clockwise and counter-clockwise) (#3086)
Also for 180 degree is expected. Rotation is not exactly like pivoting (transposing)
for instance, given the following table:
```
> echo [[col1, col2, col3]; [cell1, cell2, cell3] [cell4, cell5, cell6]]
───┬───────┬───────┬───────
# │ col1 │ col2 │ col3
───┼───────┼───────┼───────
0 │ cell1 │ cell2 │ cell3
1 │ cell4 │ cell5 │ cell6
───┴───────┴───────┴───────
```
To rotate it counter clockwise by 90 degrees, we can resort to first transposing (`pivot`)
them adding a new column (preferably integers), sort by that column from highest to lowest,
then remove the column and we have a counter clockwise rotation.
```
> echo [[col1, col2, col3]; [cell1, cell2, cell3] [cell4, cell5, cell6]] | pivot | each --numbered { = $it.item | insert idx $it.index } | sort-by idx | reverse | reject idx
───┬─────────┬─────────┬─────────
# │ Column0 │ Column1 │ Column2
───┼─────────┼─────────┼─────────
0 │ col3 │ cell3 │ cell6
1 │ col2 │ cell2 │ cell5
2 │ col1 │ cell1 │ cell4
───┴─────────┴─────────┴─────────
```
Which we can get easily, in this case, by doing:
```
> echo [[col1, col2, cel3]; [cell1, cell2, cell3] [cell4, cell5, cell6]] | rotate counter-clockwise
───┬─────────┬─────────┬─────────
# │ Column0 │ Column1 │ Column2
───┼─────────┼─────────┼─────────
0 │ col3 │ cell3 │ cell6
1 │ col2 │ cell2 │ cell5
2 │ col1 │ cell1 │ cell4
───┴─────────┴─────────┴─────────
```
There are also many powerful use cases with rotation, it makes a breeze creating tables with many columns, say:
```
echo 0..12 | rotate counter-clockwise | reject Column0
───┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┬──────────┬──────────┬──────────┬──────────
# │ Column1 │ Column2 │ Column3 │ Column4 │ Column5 │ Column6 │ Column7 │ Column8 │ Column9 │ Column10 │ Column11 │ Column12 │ Column13
───┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼──────────┼──────────┼──────────┼──────────
0 │ 0 │ 1 │ 2 │ 3 │ 4 │ 5 │ 6 │ 7 │ 8 │ 9 │ 10 │ 11 │ 12
───┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┴──────────┴──────────┴──────────┴──────────
```
2021-02-22 12:56:34 +01:00
|
|
|
mod rotate;
|
2022-03-08 02:17:33 +01:00
|
|
|
mod run_external;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod save;
|
2020-05-07 13:03:43 +02:00
|
|
|
mod select;
|
2020-04-20 08:41:51 +02:00
|
|
|
mod semicolon;
|
2022-12-07 03:48:03 +01:00
|
|
|
mod seq;
|
2022-11-10 02:06:47 +01:00
|
|
|
mod seq_char;
|
2020-07-15 03:44:49 +02:00
|
|
|
mod skip;
|
2022-12-01 14:11:30 +01:00
|
|
|
mod sort;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod sort_by;
|
2022-08-31 22:32:56 +02:00
|
|
|
mod source_env;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod split_by;
|
|
|
|
mod split_column;
|
2020-05-24 08:41:30 +02:00
|
|
|
mod split_row;
|
2020-05-27 00:19:18 +02:00
|
|
|
mod str_;
|
2022-10-03 18:40:16 +02:00
|
|
|
mod table;
|
2022-04-07 22:49:28 +02:00
|
|
|
mod take;
|
2023-11-22 03:48:39 +01:00
|
|
|
mod terminal;
|
2022-12-23 01:38:07 +01:00
|
|
|
mod to_text;
|
2020-02-18 21:54:32 +01:00
|
|
|
mod touch;
|
2022-06-23 02:19:06 +02:00
|
|
|
mod transpose;
|
2022-11-24 05:52:11 +01:00
|
|
|
mod try_;
|
use uutils/coreutils cp command in place of nushell's cp command (#10097)
<!--
if this PR closes one or more issues, you can automatically link the PR
with
them by using one of the [*linking
keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword),
e.g.
- this PR should close #xxxx
- fixes #xxxx
you can also mention related issues, PRs or discussions!
-->
# Description
Hi. Basically, this is a continuation of the work that @fdncred started.
Given some nice discussions on #9463 , and [merged uutils
PR](https://github.com/uutils/coreutils/pull/5152) from @tertsdiepraam
we have decided to give the `cp` command the `crawl` stage as it was
named.
> [!NOTE]
Given that the `uutils` crate has not made the release for the merged
PR, just make sure you checkout latest and put it in the required place
to make this PR work.
The aim of this PR is for is to see how to move forward using `uutils`
crate. In order to getting this started, I have made the current
`nushell cp tests` pass along with some extra ones I copied over from
the `uutils` repo.
With all of that being said, things that would be nice to decide, and
keep working on:
Crawl:
- Handling of certain `named` flags, with their long and short
forms(e.g. --update, --reflink, --preserve, etc), and using default
values. Maybe `-u` can already have a `default_missing_value`.
- Should we maybe just support one single option `switch` flags (see
`--backup` in code) as a contrast to the other named args.
- Complete test coverage from `uutils`. They had > 100 tests, and I
could only port like 12 as they are a bit time consuming given they
cannot be straight up copy pasted. Maybe we do not need all >100, but
maybe the more relevant to what we want.
- Refactor this code
Walk:
- Non fatal errors on `copy` from `utils`. Currently it just sends it to
stdout but errors have no span
- Better integration
An added possibility is the addition of `SyntaxShape::OneOf()` for
`Named` arguments which was briefly mentioned in the discord server, but
that is still to be decided. This could greatly improve some of the
integration. This would enable something like `cp --preserve [all
timestamp]` or `cp --preserve all` to both work.
I did not want to keep holding on this, and wait till I was happy with
the code because I think its nice if everyone can start up and suggest
refactors, but the main important part now was getting it out the door,
as if I take my sweet time this will take way longer :stuck_out_tongue:
<!--
Thank you for improving Nushell. Please, check our [contributing
guide](../CONTRIBUTING.md) and talk to the core team before making major
changes.
Description of your pull request goes here. **Provide examples and/or
screenshots** if your changes affect the user experience.
-->
# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->
# Tests + Formatting
Make sure you've run and fixed any issues with these commands:
- [X] cargo fmt --all -- --check` to check standard code formatting
(`cargo fmt --all` applies these changes)
- [X] cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to
check that you're using the standard code style
- [X] cargo test --workspace` to check that all tests pass
- [X] cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` to run the tests for the standard library
> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu # or use an `env_change` hook to activate it
automatically
> toolkit check pr
> ```
-->
# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
---------
Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
2023-09-08 20:57:38 +02:00
|
|
|
mod ucp;
|
2023-10-30 13:59:48 +01:00
|
|
|
mod umkdir;
|
2019-12-31 05:05:02 +01:00
|
|
|
mod uniq;
|
2022-12-02 11:36:01 +01:00
|
|
|
mod uniq_by;
|
2020-05-07 07:33:30 +02:00
|
|
|
mod update;
|
2022-03-17 18:55:02 +01:00
|
|
|
mod upsert;
|
2022-11-19 19:14:29 +01:00
|
|
|
mod url;
|
2022-02-18 02:58:24 +01:00
|
|
|
mod use_;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod where_;
|
2022-03-29 13:10:43 +02:00
|
|
|
#[cfg(feature = "which-support")]
|
2021-01-08 18:44:31 +01:00
|
|
|
mod which;
|
2022-11-11 19:21:45 +01:00
|
|
|
mod while_;
|
2020-05-06 05:56:31 +02:00
|
|
|
mod with_env;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod wrap;
|
2021-08-15 06:36:08 +02:00
|
|
|
mod zip;
|