Add bash auto-completion support#337
Merged
Merged
Conversation
Reviewer's GuideImplements a bash completion script for the Sequence diagram for bash completion interaction with newa CLIsequenceDiagram
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
Flow diagram for _newa_completion option and command resolutionflowchart 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]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
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.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>
a0d42e3 to
62671ba
Compare
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.
Implement comprehensive bash completion for newa command-line interface that is automatically installed with the RPM package.
Features:
Changes:
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:
Enhancements:
Build: