Route a leading "--" to the default command (#245)#1527
Open
zbl1998-sdjn wants to merge 1 commit into
Open
Conversation
`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 `--`.
There was a problem hiding this comment.
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
DefaultGroupsubclass 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.DefaultGroupimport 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 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #245.
llm -- "--find me"fails withError: No such option '--find me', while the explicitllm prompt -- "--find me"works. TheDefaultGroupconsumes the--separator before the implicit defaultpromptcommand sees it, so the text is parsed as an option.This adds a small
DefaultGroupsubclass that prepends the default command name when the first argument is--, so the separator reaches thepromptcommand 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).pytest tests/test_llm.py(69 passed) andtests/test_cli_options.py(6 passed) are green;ruff checkandblack --checkare clean.