ast: Require --help to parse more keywords as decorated statement (#10000)

This makes it so

```fish
if -e foo
    # do something
end
```

complains about `-e` not being a command instead of `end` being used
outside of an if-block.

That means both that `-e` could now be used as a command name (it
already can outside of `if`!) *and* that we get a better error!

The only way to get `if` to be a decorated statement now is to use `if
-h` or `if --help` specifically (with a literal option).

The same goes for switch, while and begin.

It would be possible, alternatively, to disallow `if -e` and point
towards using `test` instead, but the "unknown command" message should
already point towards using `test` more than pointing at the
"end" (that might be quite far away).
This commit is contained in:
Fabian Boehm
2023-09-19 17:34:13 +02:00
committed by GitHub
parent 6194899c6b
commit 4d2f7b0c0d
2 changed files with 31 additions and 8 deletions

View File

@@ -73,3 +73,19 @@ echo "bind -M" | $fish
# CHECKERR: ^
# CHECKERR: (Type 'help bind' for related documentation)
$fish -c 'if -e; end'
# CHECKERR: fish: Unknown command: -e
# CHECKERR: fish:
# CHECKERR: if -e; end
# CHECKERR: ^^
$fish -c 'begin --notanoption; end'
# CHECKERR: fish: Unknown command: --notanoption
# CHECKERR: fish:
# CHECKERR: begin --notanoption; end
# CHECKERR: ^~~~~~~~~~~~^
$fish -c 'begin --help'
# CHECKERR: fish: begin: missing man page
# CHECKERR: Documentation may not be installed.
# CHECKERR: `help begin` will show an online version