Skip to content

Route a leading "--" to the default command (#245)#1527

Open
zbl1998-sdjn wants to merge 1 commit into
simonw:mainfrom
zbl1998-sdjn:fix-dashes-default-command
Open

Route a leading "--" to the default command (#245)#1527
zbl1998-sdjn wants to merge 1 commit into
simonw:mainfrom
zbl1998-sdjn:fix-dashes-default-command

Conversation

@zbl1998-sdjn

Copy link
Copy Markdown

Fixes #245.

llm -- "--find me" fails with Error: No such option '--find me', while the explicit llm prompt -- "--find me" works. The DefaultGroup consumes the -- separator before the implicit default prompt command sees it, so the text is parsed as an option.

This adds a small DefaultGroup subclass that prepends the default command name when the first argument is --, so the separator reaches the prompt command exactly as it does for the explicit form. It only triggers when the args start with a literal --; every other invocation is unchanged.

Verification

  • llm -- "--find me" now runs the prompt (previously a usage error).
  • Added a regression test. pytest tests/test_llm.py (69 passed) and tests/test_cli_options.py (6 passed) are green; ruff check and black --check are clean.

`llm -- "--text"` failed with `Error: No such option '--text'`, while the
explicit `llm prompt -- "--text"` worked: the group consumed the `--`
separator before the implicit default `prompt` command could see it. A small
DefaultGroup subclass prepends the default command name when the first
argument is `--`, so the separator reaches the prompt command. Only affects
invocations that start with a literal `--`.
Copilot AI review requested due to automatic review settings July 12, 2026 21:24

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes a Click default-command edge case where invoking llm -- "--find me" incorrectly treats the prompt text as an option because the -- separator is consumed by the DefaultGroup before the implicit prompt command sees it.

Changes:

  • Introduce a local DefaultGroup subclass that prepends the default command name when the first argv token is a literal --, preserving the separator for the default command.
  • Switch the click_default_group.DefaultGroup import to an internal alias to support subclassing without name conflicts.
  • Add a regression test covering the llm -- "--find me" behavior (issue #245).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
llm/cli.py Adds a DefaultGroup.parse_args() override to route a leading -- to the default command so the separator reaches prompt.
tests/test_llm.py Adds a regression test ensuring a dashed prompt passed via -- works with the implicit default prompt command.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_llm.py
Comment on lines +27 to +29
result = runner.invoke(cli, ["--", "--find me"], catch_exceptions=False)
assert result.exit_code == 0, result.output
assert '"prompt": "--find me"' in result.output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

llm -- "--find me" doesn't work but llm prompt -- "--find me" does

2 participants