nushell/crates/nu-cli/src
JT 62e34b69b3
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-25 09:39:16 +13:00
..
completions Stdout/Stderr redirection (#7185) 2022-11-23 07:26:13 +13:00
menus add signature information when get help on one command (#7079) 2022-11-20 07:22:42 -06:00
commands.rs Remove perf flag to streamline logging configuration (#6834) 2022-10-21 10:20:21 -05:00
config_files.rs Run a round of clippy --fix to fix a ton of lints (#7006) 2022-11-04 15:11:17 -05:00
eval_file.rs A set of fixes for stderr redirect (#7219) 2022-11-24 16:58:15 +13:00
lib.rs Split merging of parser delta and stack environment (#6005) 2022-07-14 17:09:27 +03:00
nu_highlight.rs feat: add search terms to category of strings (#5723) 2022-06-06 08:47:09 -05:00
print.rs add -e flag to print, to print the value to stderr (#5935) 2022-07-02 09:54:49 -05:00
prompt_update.rs Split blocks and closures (#7075) 2022-11-10 21:21:49 +13:00
prompt.rs Add support to render right prompt on last line of the prompt (#6781) 2022-10-23 16:18:26 +02:00
reedline_config.rs Split blocks and closures (#7075) 2022-11-10 21:21:49 +13:00
repl.rs New commands: break, continue, return, and loop (#7230) 2022-11-25 09:39:16 +13:00
syntax_highlight.rs Stdout/Stderr redirection (#7185) 2022-11-23 07:26:13 +13:00
util.rs New "display_output" hook. (#6915) 2022-11-06 13:46:40 +13:00
validation.rs Add an alias denylist for expansions (#4871) 2022-03-19 08:03:57 +13:00