bf9395e022
CI / results (push) Blocked by required conditions
CI / license-header (push) Has been skipped
CI / e2e-dry-run (push) Has been skipped
CI / e2e-live (push) Waiting to run
CI / fast-gate (push) Failing after 0s
Test PR Label Logic / test-pr-labels (push) Failing after 1s
Skill Format Check / check-format (push) Failing after 2s
CI / security (push) Failing after 5s
CI / unit-test (push) Has been skipped
CI / lint (push) Has been skipped
CI / script-test (push) Has been skipped
CI / deterministic-gate (push) Has been skipped
CI / coverage (push) Has been skipped
CI / deadcode (push) Waiting to run
44 lines
1.3 KiB
Go
44 lines
1.3 KiB
Go
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package completion
|
|
|
|
import (
|
|
"github.com/larksuite/cli/errs"
|
|
"github.com/larksuite/cli/internal/cmdutil"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// NewCmdCompletion creates the completion command that generates shell completion scripts.
|
|
func NewCmdCompletion(f *cmdutil.Factory) *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "completion <shell>",
|
|
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 {
|
|
root := cmd.Root()
|
|
out := f.IOStreams.Out
|
|
switch args[0] {
|
|
case "bash":
|
|
return root.GenBashCompletionV2(out, true)
|
|
case "zsh":
|
|
return root.GenZshCompletion(out)
|
|
case "fish":
|
|
return root.GenFishCompletion(out, true)
|
|
case "powershell":
|
|
return root.GenPowerShellCompletionWithDesc(out)
|
|
default:
|
|
return errs.NewValidationError(errs.SubtypeInvalidArgument,
|
|
"unsupported shell: %s", args[0]).
|
|
WithHint("supported shells: bash, zsh, fish, powershell")
|
|
}
|
|
},
|
|
}
|
|
cmdutil.DisableAuthCheck(cmd)
|
|
cmdutil.SetRisk(cmd, "read")
|
|
return cmd
|
|
}
|