Skip to content

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

Merged
faho merged 2 commits into
fish-shell:masterfrom
faho:more-dash-dash-help
Sep 19, 2023
Merged

ast: Require --help to parse more keywords as decorated statement#10000
faho merged 2 commits into
fish-shell:masterfrom
faho:more-dash-dash-help

Conversation

@faho
Copy link
Copy Markdown
Member

@faho faho commented Sep 5, 2023

This makes it so

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 and while.

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).

TODOs:

  • Changes to fish usage are reflected in user documentation/manpages.
  • Tests have been added for regressions fixed
  • User-visible changes noted in CHANGELOG.rst
  • The comments here confuse me quite a bit. Have I understood the intent correctly? Do we want to change this even more?

@faho faho added this to the fish next-3.x milestone Sep 5, 2023
Copy link
Copy Markdown
Member

@ridiculousfish ridiculousfish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I think this can also be extended this to begin.

Recall that begin, for historical reasons, doesn't need a statement terminator. This is OK:

begin echo hello; end

Today begin --foo; end fails with the same "end outside of a block" but I think it should enjoy your nice fix here too.

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 and while.

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).
@faho faho force-pushed the more-dash-dash-help branch from b448e4e to b1b60e4 Compare September 19, 2023 15:16
@faho faho merged commit 4d2f7b0 into fish-shell:master Sep 19, 2023
@faho faho deleted the more-dash-dash-help branch September 19, 2023 15:34
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Sep 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants