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_;
|
special-case ExternalStream in bytes starts-with (#8203)
# Description
`bytes starts-with` converts the input into a `Value` before running
.starts_with to find if the binary matches. This has two side effects:
it makes the code simpler, only dealing in whole values, and simplifying
a lot of input pipeline handling and value transforming it would
otherwise have to do. _Especially_ in the presence of a cell path to
drill into. It also makes buffers the entire input into memory, which
can take up a lot of memory when dealing with large files, especially if
you only want to check the first few bytes (like for a magic number).
This PR adds a special branch on PipelineData::ExternalStream with a
streaming version of starts_with.
# User-Facing Changes
Opening large files and running bytes starts-with on them will not take
a long time.
# 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
# Drawbacks
Streaming checking is more complicated, and there may be bugs. I tested
it with multiple chunks with string data and binary data and it seems to
work alright up to 8k and over bytes, though.
The existing `operate` method still exists because the way it handles
cell paths and values is complicated. This causes some "code
duplication", or at least some intent duplication, between the value
code and the streaming code. This might be worthwhile considering the
performance gains (approaching infinity on larger inputs).
Another thing to consider is that my ExternalStream branch considers
string data as valid input. The operate branch only parses Binary
values, so it would fail. `open` is kind of unpredictable on whether it
returns string data or binary data, even when passing `--raw`. I think
this can be a problem but not really one I'm trying to tackle in this
PR, so, it's worth considering.
2023-02-26 15:17:44 +01:00
|
|
|
mod bytes;
|
2020-05-10 01:05:48 +02:00
|
|
|
mod cal;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod cd;
|
|
|
|
mod compact;
|
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_;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod cp;
|
2022-05-23 18:59:34 +02:00
|
|
|
mod date;
|
2021-01-07 18:14:51 +01:00
|
|
|
mod def;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod default;
|
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;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod enter;
|
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
|
|
|
#[cfg(not(windows))]
|
|
|
|
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_;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod format;
|
2022-08-06 14:09:14 +02:00
|
|
|
mod g;
|
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;
|
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;
|
2020-07-06 17:27:01 +02:00
|
|
|
mod move_;
|
2022-11-11 07:51:08 +01:00
|
|
|
mod mut_;
|
2022-08-07 20:30:40 +02:00
|
|
|
mod n;
|
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;
|
2022-08-07 20:30:40 +02:00
|
|
|
mod p;
|
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;
|
2021-02-23 19:29:07 +01:00
|
|
|
mod roll;
|
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;
|
2022-08-08 13:31:24 +02:00
|
|
|
mod shells;
|
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;
|
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_;
|
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;
|