Skip to content

tab complete root flags if - or -- provided, otherwise complete comma…#379

Merged
kindermax merged 2 commits into
masterfrom
improve-zsh-completions
Jun 22, 2026
Merged

tab complete root flags if - or -- provided, otherwise complete comma…#379
kindermax merged 2 commits into
masterfrom
improve-zsh-completions

Conversation

@kindermax

@kindermax kindermax commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

…nds or command flags

Summary by Sourcery

Improve zsh completion behavior for root flags and commands in the lets CLI.

Bug Fixes:

  • Ensure zsh completion correctly handles root-level flags before command names, preventing errors like command -c not declared in config during completion.

Documentation:

  • Document the zsh completion fix in the changelog, noting improved handling of root flags and removal of erroneous config command errors.

@sourcery-ai

sourcery-ai Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Updates the zsh completion script for the lets CLI to correctly handle root flags before command names and propagates those flags into completion subcommands, while documenting the fix in the changelog.

Sequence diagram for updated zsh completion root flag handling

sequenceDiagram
    participant User
    participant zsh as zsh_completion
    participant _lets
    participant _lets_root_flags_before_command
    participant _check_lets_config
    participant lets as LETS_EXECUTABLE

    User->>zsh: Press TAB after lets -c custom.yaml cmd
    zsh->>_lets: _lets
    _lets->>_lets_root_flags_before_command: _lets_root_flags_before_command
    _lets_root_flags_before_command-->>_lets: reply (root_flags)

    _lets->>_check_lets_config: _check_lets_config root_flags
    _check_lets_config->>lets: lets root_flags completion --commands --verbose
    lets-->>_check_lets_config: exit_code
    _check_lets_config-->>_lets: exit_code

    alt commands completion
        _lets->>lets: lets root_flags completion --commands --verbose
        lets-->>_lets: command_list
    else options completion
        _lets->>lets: lets root_flags completion --options=cmd --verbose
        lets-->>_lets: option_list
    end
Loading

File-Level Changes

Change Details Files
Enhance zsh completion to understand and propagate root flags before command names.
  • Add zsh _arguments specs for root-level flags such as --config, --env, --only, --exclude, debug, --all, and --init.
  • Introduce _lets_root_flags_before_command to extract root flags appearing before the command token, handling both separate and combined forms (e.g., --config foo and --config=foo).
  • Introduce _lets_active_command to determine the active command name, skipping over recognized root flags and options.
  • Update _lets_commands to compute root flags and pass them both to _check_lets_config and the lets completion --commands call, suppressing stderr from the executable.
  • Update _lets_command_options to guard against missing/option-like commands and to forward root flags into the lets completion --options call, suppressing stderr.
  • Extend _check_lets_config to accept and forward arbitrary arguments to the lets executable.
internal/cmd/completion.go
Document the zsh completion root flag handling fix in the changelog.
  • Add a changelog entry describing the fix for zsh completion handling of root flags and suppression of erroneous command -c not declared in config messages.
docs/docs/changelog.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • The flag-handling logic in _lets_root_flags_before_command and _lets_active_command duplicates the same case patterns; consider centralizing the supported root flags in a shared helper or data structure to keep them from drifting out of sync.
  • The updated _check_lets_config now accepts arbitrary arguments and is used in multiple places; it might be clearer to document or enforce that it only expects root flags so accidental non-flag arguments don’t produce surprising behavior.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The flag-handling logic in `_lets_root_flags_before_command` and `_lets_active_command` duplicates the same case patterns; consider centralizing the supported root flags in a shared helper or data structure to keep them from drifting out of sync.
- The updated `_check_lets_config` now accepts arbitrary arguments and is used in multiple places; it might be clearer to document or enforce that it only expects root flags so accidental non-flag arguments don’t produce surprising behavior.

## Individual Comments

### Comment 1
<location path="internal/cmd/completion.go" line_range="58" />
<code_context>
+	_lets_active_command() {
</code_context>
<issue_to_address>
**suggestion:** Consider treating `--` as a hard stop when determining the active command.

In `_lets_active_command`, `--` is currently treated like other flags and skipped:
```sh
		case "$token" in
			-c|--config|-E|--env|--only|--exclude)
				((idx++))
				;;
			--config=*|--env=*|--only=*|--exclude=*|-E*|-d|-dd|--debug|--all|--init|--)
				;;
```
But `_lets_root_flags_before_command` uses `--` as a terminator. To keep behavior consistent and avoid mis-identifying a post-`--` argument as the command, `_lets_active_command` should `break` when it sees `--` instead of skipping it.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread internal/cmd/completion.go Outdated
@kindermax kindermax merged commit b7af238 into master Jun 22, 2026
5 checks passed
@kindermax kindermax deleted the improve-zsh-completions branch June 22, 2026 14:30
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.

1 participant