Skip to content

feat: add shell completion support with enum flag validation#20

Open
ZhexuanHu wants to merge 1 commit intolarksuite:mainfrom
ZhexuanHu:feat/shell-completion
Open

feat: add shell completion support with enum flag validation#20
ZhexuanHu wants to merge 1 commit intolarksuite:mainfrom
ZhexuanHu:feat/shell-completion

Conversation

@ZhexuanHu
Copy link
Copy Markdown

Summary

Enhance existing shell completion support:

  • Improve completion command: add -s/--shell flag with input validation, TTY detection (defaults to bash when piped), unhide from help output
  • Add NoFileCompletion() and RegisterEnumFlag() reusable utilities in internal/cmdutil/completion.go
  • Apply NoFileCompletion to all leaf commands without positional args (auth/, config/, doctor, service methods)
  • --as and --format flags now validate input at parse time and provide tab-completion for valid values
  • Add unit tests for completion utilities (8 test cases)

This 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 completion command syntax changes from positional arg (completion bash) to flag (completion -s bash). The previous command was hidden and undocumented.

Usage

# 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 — quick start (current session only)                                                                                                                                                                                                                                       
source <(lark-cli completion -s zsh)
                                                                                                                                                                                                                                                                                 
# Zsh — persistent
mkdir -p ~/.zsh/completions
lark-cli completion -s zsh > ~/.zsh/completions/_lark-cli
# add to ~/.zshrc:                                                                                                                                                                                                                                                               
#   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                                                                                                                                                                                                               

Test plan

  • go test ./... all pass (0 failures)
  • lark-cli completion -s bash/zsh/fish/powershell generates valid scripts
  • lark-cli __complete "" returns subcommand candidates
  • lark-cli __complete api --format "" returns enum candidates
  • lark-cli __complete schema "calendar." returns resource candidates
  • Invalid enum values (--as invalid, -s invalid) rejected at parse time
  • Leaf commands (auth/, config/, doctor) return no file candidates

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.
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 30, 2026

CLA assistant check
All committers have signed the CLA.

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.

2 participants