Skip to content

Commit 717b5d1

Browse files
Added shell completion subcommand (#271)
* Added shell completion subcommand Signed-off-by: Christian Hernandez <chernand@redhat.com> * wip * wip * bump * bump * trigger ci Co-authored-by: roi-codefresh <roi.kramer@codefresh.io>
1 parent 6384006 commit 717b5d1

File tree

5 files changed

+58
-4
lines changed

5 files changed

+58
-4
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=v0.0.251
1+
VERSION=v0.0.253
22

33
OUT_DIR=dist
44
YEAR?=$(shell date +"%Y")

cmd/commands/completion.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
}

cmd/commands/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ variables in advanced to simplify the use of those commands.
5656
cmd.AddCommand(NewWorkflowCommand())
5757
cmd.AddCommand(NewPipelineCommand())
5858
cmd.AddCommand(NewIntegrationCommand())
59+
cmd.AddCommand(NewCompletionCommand())
5960

6061
cobra.OnInitialize(func() { postInitCommands(cmd.Commands()) })
6162

docs/releases/release_notes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ cf version
2323

2424
```bash
2525
# download and extract the binary
26-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.251/cf-linux-amd64.tar.gz | tar zx
26+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.253/cf-linux-amd64.tar.gz | tar zx
2727

2828
# move the binary to your $PATH
2929
mv ./cf-linux-amd64 /usr/local/bin/cf
@@ -36,7 +36,7 @@ cf version
3636

3737
```bash
3838
# download and extract the binary
39-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.251/cf-darwin-amd64.tar.gz | tar zx
39+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.253/cf-darwin-amd64.tar.gz | tar zx
4040

4141
# move the binary to your $PATH
4242
mv ./cf-darwin-amd64 /usr/local/bin/cf

manifests/runtime.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
namespace: "{{ namespace }}"
66
spec:
77
defVersion: 1.0.1
8-
version: 0.0.251
8+
version: 0.0.253
99
bootstrapSpecifier: github.com/codefresh-io/cli-v2/manifests/argo-cd
1010
components:
1111
- name: events

0 commit comments

Comments
 (0)