feat: add shell completion support with enum flag validation#20
Open
ZhexuanHu wants to merge 1 commit intolarksuite:mainfrom
Open
feat: add shell completion support with enum flag validation#20ZhexuanHu wants to merge 1 commit intolarksuite:mainfrom
ZhexuanHu wants to merge 1 commit intolarksuite:mainfrom
Conversation
Add comprehensive shell auto-completion for lark-cli, covering
subcommands, flags, and dynamic values (schema paths, enum options).
Changes:
- Add NoFileCompletion() and RegisterEnumFlag() utilities in
internal/cmdutil/completion.go for reusable completion patterns
- Rewrite completion command to use -s/--shell flag with enum
validation and TTY detection (defaults to bash when piped)
- Apply NoFileCompletion to all leaf commands that do not accept
positional arguments (auth/*, config/*, doctor)
- Convert --as and --format flags to RegisterEnumFlag for
parse-time validation with automatic shell completion
- Add unit tests for completion utilities
- Update service test to expect parse-time rejection of invalid
format values
Usage — enable shell completion:
Bash (Linux):
lark-cli completion -s bash > ~/.local/share/bash-completion/completions/lark-cli
Bash (macOS + Homebrew):
lark-cli completion -s bash > $(brew --prefix)/etc/bash_completion.d/lark-cli
Zsh (macOS / Linux):
# quick start (current session only):
source <(lark-cli completion -s zsh)
# persistent:
mkdir -p ~/.zsh/completions
lark-cli completion -s zsh > ~/.zsh/completions/_lark-cli
# ensure ~/.zshrc contains:
# fpath=(~/.zsh/completions $fpath)
# autoload -U compinit; compinit
Fish:
lark-cli completion -s fish > ~/.config/fish/completions/lark-cli.fish
PowerShell:
lark-cli completion -s powershell | Out-String | Invoke-Expression
# to persist, add the above line to your $PROFILE
Note on macOS PATH precedence:
If lark-cli was installed via both npm (installs to /opt/homebrew/bin
on Apple Silicon) and `make install` (defaults to /usr/local/bin),
the shell may resolve the wrong binary. Run `which lark-cli` to
verify, or use `make install PREFIX=$(brew --prefix)` to install
into the same directory as npm.
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.
Summary
Enhance existing shell completion support:
completioncommand: add-s/--shellflag with input validation, TTY detection (defaults to bash when piped), unhide from help outputNoFileCompletion()andRegisterEnumFlag()reusable utilities ininternal/cmdutil/completion.goNoFileCompletionto all leaf commands without positional args (auth/, config/, doctor, service methods)--asand--formatflags now validate input at parse time and provide tab-completion for valid valuesThis is a non-breaking enhancement — completion only activates when users explicitly configure it. Existing CLI behavior is unchanged for users who do not enable completion.
Note: the
completioncommand syntax changes from positional arg (completion bash) to flag (completion -s bash). The previous command was hidden and undocumented.Usage
Test plan
go test ./...all pass (0 failures)lark-cli completion -s bash/zsh/fish/powershellgenerates valid scriptslark-cli __complete ""returns subcommand candidateslark-cli __complete api --format ""returns enum candidateslark-cli __complete schema "calendar."returns resource candidates--as invalid,-s invalid) rejected at parse time