Skip to content

Add bash auto-completion support#337

Merged
kkaarreell merged 1 commit into
mainfrom
ks_completion
Apr 1, 2026
Merged

Add bash auto-completion support#337
kkaarreell merged 1 commit into
mainfrom
ks_completion

Conversation

@kkaarreell

@kkaarreell kkaarreell commented Apr 1, 2026

Copy link
Copy Markdown
Collaborator

Implement comprehensive bash completion for newa command-line interface that is automatically installed with the RPM package.

Features:

  • Complete all global options and subcommands
  • Command-specific option completion for each subcommand
  • Support for command chaining (completes based on last command)
  • File/directory completion with proper trailing slashes
  • Predefined value completion (architectures, test results)
  • Auto-installed via RPM to /usr/share/bash-completion/completions/newa

Changes:

  • Add newa-completion.bash: Comprehensive completion script
  • Update pyproject.toml: Include completion script in sdist
  • Update newa.spec: Install and package completion file
  • Update README.md: Document bash completion usage

The completion script uses bash's filenames mode for proper directory handling and finds the last command in a chain to provide context-aware suggestions for newa's command chaining feature.

🤖 Generated with Claude Code

Summary by Sourcery

Add Bash completion support for the newa CLI and package it with the RPM distribution.

New Features:

  • Provide comprehensive Bash tab-completion for newa commands, global options, subcommand-specific options, and selected option values such as architectures and results.

Enhancements:

  • Document Bash completion usage and examples in the README, including how to enable it immediately in a shell session.

Build:

  • Include the Bash completion script in the source distribution via pyproject.toml and install it into the system bash-completion directory from the RPM spec.

@kkaarreell kkaarreell self-assigned this Apr 1, 2026
@sourcery-ai

sourcery-ai Bot commented Apr 1, 2026

Copy link
Copy Markdown

Reviewer's Guide

Implements a bash completion script for the newa CLI, wires it into packaging so it is installed via the RPM, and documents how to use it in the README, including context-aware subcommand/option/value completions and command chaining support.

Sequence diagram for bash completion interaction with newa CLI

sequenceDiagram
    actor User
    participant BashShell
    participant BashCompletion as Bash_Completion_Framework
    participant NewaCompletion as _newa_completion

    User->>BashShell: Type "newa ..." and press TAB
    BashShell->>BashCompletion: Trigger completion for command newa
    BashCompletion->>NewaCompletion: Call _newa_completion with COMP_WORDS and COMP_CWORD
    NewaCompletion->>NewaCompletion: Determine cur and prev from COMP_WORDS
    NewaCompletion->>NewaCompletion: Identify last subcommand from commands
    alt Completing option value
        NewaCompletion->>NewaCompletion: Match prev against value-expecting options
        NewaCompletion-->>BashCompletion: Set COMPREPLY with files or predefined values
    else Completing options or subcommands
        NewaCompletion->>NewaCompletion: If before any command, offer main_opts or commands
        NewaCompletion->>NewaCompletion: If after a command, offer command-specific options
        NewaCompletion->>NewaCompletion: Also offer next commands for chaining
        NewaCompletion-->>BashCompletion: Set COMPREPLY with candidates
    end
    BashCompletion-->>BashShell: Provide completion suggestions
    BashShell-->>User: Display or insert completed text
Loading

Flow diagram for _newa_completion option and command resolution

flowchart TD
    A[Start _newa_completion
    read COMP_WORDS and COMP_CWORD] --> B[Set cur and prev]
    B --> C{Does prev
    expect a value?}

    C -->|File/dir options
    --state-dir -D --extract-state-dir -E --conf-file --issue-config --job-recipe| D[Use compgen -f
    for cur]
    C -->|--arch| E[Use compgen -W arch_values
    x86_64 aarch64 ppc64le s390x]
    C -->|--restart-result -r| F[Use compgen -W result_values
    passed failed error]
    C -->|Numeric options
    --workers --last| G[Return
    allow free numeric input]
    C -->|Other value options
    erratum compose jira-issue etc| H[Return
    user-provided value]

    D --> Z[Set COMPREPLY and return]
    E --> Z
    F --> Z
    G --> Z
    H --> Z

    C -->|No
    prev does not expect value| I[Scan COMP_WORDS
    find last subcommand
    from commands]

    I --> J{Found cmd?}

    J -->|No
    before first command| K{Is cur an option?}
    K -->|Yes| L[Complete from main_opts]
    K -->|No| M[Complete from commands]
    L --> Z
    M --> Z

    J -->|Yes
    after a command| N{cmd is
    event jira schedule
    execute report cancel
    summarize list}

    N --> O[If cur starts with -
    complete from command-specific opts]
    N --> P[If cur is not option
    complete from commands
    for chaining]

    O --> Z
    P --> Z

    Z[COMPREPLY set
    return 0]
Loading

File-Level Changes

Change Details Files
Add context-aware bash completion script for the newa CLI, including command chaining and value/file completions.
  • Introduce _newa_completion bash function that inspects COMP_WORDS/COMP_CWORD and populates COMPREPLY for the newa command.
  • Define global options, per-subcommand option sets, and predefined value lists (architectures, restart results) to drive completions.
  • Handle options that take files/directories via compgen -f, numeric/opaque arguments by returning no completions, and enumerate valid values for --arch and --restart-result.
  • Walk the argument vector to find the last subcommand in a chain and tailor subsequent completions based on that command.
  • Register the completion handler with complete -o filenames -F _newa_completion newa so bash treats directory/file names correctly.
newa-completion.bash
Install and package the bash completion script with the RPM and source distribution.
  • In the spec file, install newa-completion.bash into %{_datadir}/bash-completion/completions/newa during %install.
  • Add the installed completion file to the %files list so it is included in the newa RPM payload.
  • Update pyproject.toml include section to ship newa-completion.bash in the sdist/wheel.
newa.spec
pyproject.toml
Document bash completion usage and examples in the project README.
  • Add a "Bash Auto-Completion" section explaining that RPM installs completion automatically and how to source it manually.
  • Provide example invocations showing subcommand, option, and architecture completions via TAB.
README.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

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The completion logic only suggests command-specific options once a subcommand is detected; if NEWA allows global flags (e.g. --debug, --state-dir) to appear after subcommands, consider including main_opts in the per-command completion lists so those remain discoverable anywhere on the command line.
  • The completion script hardcodes all commands and options in multiple string blocks, which can easily drift from the actual CLI; consider centralizing these into a single data structure or generating them from the CLI help output to reduce the maintenance burden when commands/options change.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The completion logic only suggests command-specific options once a subcommand is detected; if NEWA allows global flags (e.g. --debug, --state-dir) to appear after subcommands, consider including main_opts in the per-command completion lists so those remain discoverable anywhere on the command line.
- The completion script hardcodes all commands and options in multiple string blocks, which can easily drift from the actual CLI; consider centralizing these into a single data structure or generating them from the CLI help output to reduce the maintenance burden when commands/options change.

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.

Implement bash completion that automatically stays in sync with the CLI
by extracting commands and options from newa's help output at runtime.

Features:
- Dynamically extracts commands from 'newa --help'
- Dynamically extracts options from command-specific help
- Support for command chaining (completes based on last command)
- File/directory completion with proper trailing slashes
- Predefined value completion for architectures and test results
- Auto-installed via RPM to /usr/share/bash-completion/completions/newa

Benefits:
- Zero maintenance: automatically picks up new commands/options
- Always in sync with actual CLI implementation
- Reduced from 240 to 100 lines of code
- Only hardcodes domain-specific values (arch types, result values)

Changes:
- Add newa-completion.bash: Dynamic completion script
- Update pyproject.toml: Include completion script in sdist
- Update newa.spec: Install and package completion file
- Update README.md: Document bash completion usage

The completion script parses help output to extract available commands
and options, eliminating the need to manually update the script when
the CLI changes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@kkaarreell kkaarreell merged commit 3a5bf27 into main Apr 1, 2026
18 checks passed
@kkaarreell kkaarreell deleted the ks_completion branch April 1, 2026 09:49
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