diff --git a/README.md b/README.md index 6107ff0d..c0bc9710 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,19 @@ lark-cli auth login --recommend lark-cli calendar +agenda ``` +#### Optional: Shell Completion + +`lark-cli completion` is available as a regular top-level command and does not require login. Generate a completion script for the shell you use most: + +```bash +# Bash +lark-cli completion bash > ~/.local/share/bash-completion/completions/lark-cli + +# Zsh +mkdir -p ~/.zfunc +lark-cli completion zsh > ~/.zfunc/_lark-cli +``` + ## Quick Start (AI Agent) > The following steps are for AI Agents. Some steps require the user to complete actions in a browser. @@ -126,6 +139,12 @@ lark-cli auth login --recommend lark-cli auth status ``` +Shell completion is also available without authentication: + +```bash +lark-cli completion fish > ~/.config/fish/completions/lark-cli.fish +``` + ## Agent Skills | Skill | Description | diff --git a/README.zh.md b/README.zh.md index 4d526186..5896eea5 100644 --- a/README.zh.md +++ b/README.zh.md @@ -90,6 +90,19 @@ lark-cli auth login --recommend lark-cli calendar +agenda ``` +#### 可选:Shell Completion + +`lark-cli completion` 是一个普通的顶层命令,不需要先登录。可以为常用 shell 生成补全脚本: + +```bash +# Bash +lark-cli completion bash > ~/.local/share/bash-completion/completions/lark-cli + +# Zsh +mkdir -p ~/.zfunc +lark-cli completion zsh > ~/.zfunc/_lark-cli +``` + ### 快速开始(AI Agent) > 以下步骤面向 AI Agent,部分步骤需要用户在浏览器中配合完成。 @@ -126,6 +139,12 @@ lark-cli auth login --recommend lark-cli auth status ``` +Shell completion 也不依赖认证: + +```bash +lark-cli completion fish > ~/.config/fish/completions/lark-cli.fish +``` + ## Agent Skills diff --git a/cmd/completion/completion.go b/cmd/completion/completion.go index 574365b7..3c043734 100644 --- a/cmd/completion/completion.go +++ b/cmd/completion/completion.go @@ -16,7 +16,6 @@ func NewCmdCompletion(f *cmdutil.Factory) *cobra.Command { Use: "completion ", Short: "Generate shell completion scripts", Long: "Generate shell completion scripts for bash, zsh, fish, or powershell.", - Hidden: true, ValidArgs: []string{"bash", "zsh", "fish", "powershell"}, Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { diff --git a/cmd/completion/completion_test.go b/cmd/completion/completion_test.go new file mode 100644 index 00000000..c920ad57 --- /dev/null +++ b/cmd/completion/completion_test.go @@ -0,0 +1,23 @@ +// Copyright (c) 2026 Lark Technologies Pte. Ltd. +// SPDX-License-Identifier: MIT + +package completion + +import ( + "testing" + + "github.com/larksuite/cli/internal/cmdutil" +) + +func TestNewCmdCompletion_IsVisibleAndAuthFree(t *testing.T) { + f, _, _, _ := cmdutil.TestFactory(t, nil) + + cmd := NewCmdCompletion(f) + if cmd.Hidden { + t.Fatal("expected completion command to be visible") + } + if !cmdutil.IsAuthCheckDisabled(cmd) { + t.Fatal("expected completion command to skip auth checks") + } +} +