nushell/crates/nu-command/tests/commands
JT 13515c5eb0
Limited mutable variables (#7089)
This adds support for (limited) mutable variables. Mutable variables are created with mut much the same way immutable variables are made with let.

Mutable variables allow mutation via the assignment operator (=).

❯ mut x = 100
❯ $x = 200
❯ print $x
200

Mutable variables are limited in that they're only tended to be used in the local code block. Trying to capture a local variable will result in an error:

❯ mut x = 123; {|| $x }
Error: nu::parser::expected_keyword (link)

  × Capture of mutable variable.

The intent of this limitation is to reduce some of the issues with mutable variables in general: namely they make code that's harder to reason about. By reducing the scope that a mutable variable can be used it, we can help create local reasoning about them.

Mutation can occur with fields as well, as in this case:

❯ mut y = {abc: 123}
❯ $y.abc = 456
❯ $y

On a historical note: mutable variables are something that we resisted for quite a long time, leaning as much as we could on the functional style of pipelines and dataflow. That said, we've watched folks struggle to work with reduce as an approximation for patterns that would be trivial to express with local mutation. With that in mind, we're leaning towards the happy path.
2022-11-11 19:51:08 +13:00
..
date Require input for date format (#7043) 2022-11-10 11:16:14 +13:00
hash_ Deprecate hash base64, extend decode and add encode commands (#5863) 2022-06-26 00:35:23 +03:00
math make ++ append lists (#6766) 2022-10-20 23:28:18 +13:00
move_ Make default for mv safer, require -f to overwrite (#6904) 2022-10-29 22:16:29 +02:00
network Clippy fix for Rust 1.63 (#6299) 2022-08-11 11:54:54 -05:00
path add -n for path expand, so it doesn't follow symlink (#6255) 2022-08-10 08:43:56 -05:00
platform Return error when kill didn't terminate successfully (#6354) 2022-08-18 11:58:51 -05:00
query Revert query command to query db (#6200) 2022-07-31 15:36:14 -04:00
random Another batch of command tests (#4496) 2022-02-16 07:38:02 -05:00
skip str collect => str join (#6531) 2022-09-11 11:48:27 +03:00
str_ Eval external command result immediately when using do command with -c (#6645) 2022-09-30 07:14:02 -05:00
take make take behave like first (#6893) 2022-11-09 11:32:16 +01:00
alias.rs let alias list aliases (#6717) 2022-10-14 21:51:44 +02:00
all.rs Fixed $in in where blocks (#6976) 2022-11-10 11:05:15 +13:00
any.rs Fixed $in in where blocks (#6976) 2022-11-10 11:05:15 +13:00
append.rs Strip trailing whitespace in files (#4575) 2022-02-21 08:38:15 -05:00
cal.rs Remove old nushell/merge engine-q 2022-02-07 14:54:06 -05:00
cd.rs fix: fixcd (#6799) 2022-11-05 07:38:39 +13:00
compact.rs Remove old nushell/merge engine-q 2022-02-07 14:54:06 -05:00
cp.rs Add decimals to int when using into string --decimals (#6085) 2022-08-12 21:13:50 -05:00
def.rs Move from source to source-env (#6277) 2022-09-01 08:32:56 +12:00
default.rs Remove old nushell/merge engine-q 2022-02-07 14:54:06 -05:00
do_.rs Bump to 0.70 (#6800) 2022-10-19 07:13:36 +13:00
drop.rs Rename all?, any? and empty? (#6464) 2022-09-05 16:41:06 +02:00
each.rs str collect => str join (#6531) 2022-09-11 11:48:27 +03:00
echo.rs Require block params (#4505) 2022-02-17 06:40:24 -05:00
empty.rs Fix $in in blocks given to any and all (#6951) 2022-11-01 11:36:54 -07:00
enter.rs Remove old nushell/merge engine-q 2022-02-07 14:54:06 -05:00
error_make.rs add unspanned flag to error make, add tests (#6017) 2022-07-12 06:03:50 -05:00
every.rs Another batch of command tests (#4496) 2022-02-16 07:38:02 -05:00
export_def.rs allow -h flags for export subcommands (#6189) 2022-08-02 10:26:16 -05:00
find.rs Use 'table' on scripts and -c commands (#4377) 2022-02-09 05:58:54 -05:00
first.rs make first behave same way as last: always return list when with number argument (#6616) 2022-09-28 17:08:17 -05:00
flatten.rs str collect => str join (#6531) 2022-09-11 11:48:27 +03:00
format.rs Refactor: introduce general operate commands to reduce duplicate code (#6879) 2022-10-29 16:29:46 -05:00
g.rs Make g - switch to the last used shell (#6249) 2022-08-06 10:11:03 -05:00
get.rs Friendly error message for access beyond end (#6944) 2022-10-29 19:47:50 +02:00
glob.rs Filter out empty glob patterns to "glob" command (#6707) 2022-10-15 18:00:38 +02:00
group_by.rs more test fixes (#4499) 2022-02-16 12:24:45 -06:00
headers.rs Type validation for headers command (#6918) (#7047) 2022-11-09 16:43:24 -08:00
help.rs Clean up tests and unused documentation code (#5273) 2022-04-21 06:13:58 -05:00
histogram.rs add quantile column (#5583) 2022-05-18 20:47:26 -05:00
insert.rs Add insert/update to lists (#4873) 2022-03-19 10:12:54 +13:00
into_filesize.rs fix overflow on negative bytes (#7070) 2022-11-10 22:33:15 +01:00
into_int.rs Binary into int (#5941) 2022-07-04 06:31:50 +12:00
last.rs make first behave same way as last: always return list when with number argument (#6616) 2022-09-28 17:08:17 -05:00
length.rs Remove old nushell/merge engine-q 2022-02-07 14:54:06 -05:00
let_.rs Limited mutable variables (#7089) 2022-11-11 19:51:08 +13:00
lines.rs make first behave same way as last: always return list when with number argument (#6616) 2022-09-28 17:08:17 -05:00
ls.rs Run a round of clippy --fix to fix a ton of lints (#7006) 2022-11-04 15:11:17 -05:00
merge.rs Update merge to also take single records (#6919) 2022-10-27 09:00:26 -07:00
mkdir.rs Remove old nushell/merge engine-q 2022-02-07 14:54:06 -05:00
mod.rs Limited mutable variables (#7089) 2022-11-11 19:51:08 +13:00
mut_.rs Limited mutable variables (#7089) 2022-11-11 19:51:08 +13:00
n.rs Refactor shell switching related code (#6258) 2022-08-07 13:30:40 -05:00
nu_check.rs Removes export env command (#6468) 2022-09-25 19:52:43 +03:00
open.rs command open returns error when does not have parameters (#7048) (#7058) 2022-11-10 00:25:32 +01:00
p.rs Refactor shell switching related code (#6258) 2022-08-07 13:30:40 -05:00
parse.rs replace the regex crate with the fancy-regex crate (#6227) 2022-08-04 14:51:02 -05:00
prepend.rs Use 'table' on scripts and -c commands (#4377) 2022-02-09 05:58:54 -05:00
print.rs add -e flag to print, to print the value to stderr (#5935) 2022-07-02 09:54:49 -05:00
range.rs Use 'table' on scripts and -c commands (#4377) 2022-02-09 05:58:54 -05:00
reduce.rs feat: apply the --numbered option to acc in reduce command. (#5575) 2022-05-18 09:49:34 -05:00
reject.rs str collect => str join (#6531) 2022-09-11 11:48:27 +03:00
rename.rs add rename (#5534) 2022-05-13 06:47:11 -05:00
reverse.rs make first behave same way as last: always return list when with number argument (#6616) 2022-09-28 17:08:17 -05:00
rm.rs make cd, cp, ls, mv, open and rm automatically strip ansi codes (#6220) 2022-08-04 06:59:20 -05:00
roll.rs str collect => str join (#6531) 2022-09-11 11:48:27 +03:00
rotate.rs str collect => str join (#6531) 2022-09-11 11:48:27 +03:00
run_external.rs add some float operations with filesize (#6618) 2022-09-28 17:07:50 -05:00
save.rs Further edits to help messages (#6913) 2022-10-26 09:36:42 -07:00
select.rs Fix ignore-errors for select (#6896) 2022-11-10 10:57:44 +13:00
semicolon.rs Remove old nushell/merge engine-q 2022-02-07 14:54:06 -05:00
seq_char.rs Simplify seq char (#7054) 2022-11-09 17:06:47 -08:00
shells.rs Refactor shell listing related code (#6262) 2022-08-08 06:31:24 -05:00
sort_by.rs Require column name(s) in sort-by (#7041) 2022-11-10 11:16:51 +13:00
sort.rs Require column name(s) in sort-by (#7041) 2022-11-10 11:16:51 +13:00
source_env.rs Improve erroring of config nu and config env (#6730) 2022-10-15 08:28:54 -05:00
split_by.rs Remove old nushell/merge engine-q 2022-02-07 14:54:06 -05:00
split_column.rs refactor: change column names from 'Column*' to 'column*' (#4556) 2022-02-19 19:26:47 -05:00
split_row.rs Remove old nushell/merge engine-q 2022-02-07 14:54:06 -05:00
table.rs table/ Fix paging indexing (#6850) 2022-10-21 18:02:25 +02:00
touch.rs remove -d and -t from touch (#6629) 2022-09-28 13:48:34 +13:00
transpose.rs Prevents duplicate fields in transpose -r (#5840) 2022-06-22 19:19:06 -05:00
uniq.rs Fix Value::Record compare logic, and pass uniq tests. (#5541) 2022-05-14 06:04:09 -05:00
update.rs Add insert/update to lists (#4873) 2022-03-19 10:12:54 +13:00
upsert.rs Add insert and update back (#4864) 2022-03-18 06:55:02 +13:00
use_.rs add more helpful error for calling a decl that exists in a module (#6752) 2022-10-22 11:41:31 -05:00
where_.rs Fixed $in in where blocks (#6976) 2022-11-10 11:05:15 +13:00
which.rs Don't assume external ls (#4925) 2022-03-24 16:42:41 +13:00
with_env.rs fixed some more tests (#4607) 2022-02-22 11:32:29 -05:00
wrap.rs Use 'table' on scripts and -c commands (#4377) 2022-02-09 05:58:54 -05:00
zip.rs str collect => str join (#6531) 2022-09-11 11:48:27 +03:00