|
| 1 | +// Copyright 2022 The Codefresh Authors. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package commands |
| 16 | + |
| 17 | +import ( |
| 18 | + "os" |
| 19 | + |
| 20 | + "github.com/codefresh-io/cli-v2/pkg/util" |
| 21 | + |
| 22 | + "github.com/spf13/cobra" |
| 23 | +) |
| 24 | + |
| 25 | +func NewCompletionCommand() *cobra.Command { |
| 26 | + cmd := &cobra.Command{ |
| 27 | + Use: "completion [bash|zsh|fish|powershell]", |
| 28 | + Short: "Generates shell completion script.", |
| 29 | + Args: cobra.ExactArgs(1), |
| 30 | + Long: util.Doc(`Generates shell completion script for your shell environment |
| 31 | +
|
| 32 | +Example: |
| 33 | +
|
| 34 | + source <(<BIN> completion bash) |
| 35 | +`), |
| 36 | + RunE: func(cmd *cobra.Command, args []string) error { |
| 37 | + switch args[0] { |
| 38 | + case "bash": |
| 39 | + return cmd.Root().GenBashCompletion(os.Stdout) |
| 40 | + case "zsh": |
| 41 | + return cmd.Root().GenZshCompletion(os.Stdout) |
| 42 | + case "fish": |
| 43 | + return cmd.Root().GenFishCompletion(os.Stdout, true) |
| 44 | + case "powershell": |
| 45 | + return cmd.Root().GenPowerShellCompletion(os.Stdout) |
| 46 | + default: |
| 47 | + return cmd.Help() |
| 48 | + } |
| 49 | + }, |
| 50 | + } |
| 51 | + |
| 52 | + return cmd |
| 53 | +} |
0 commit comments