Skip to content

Commit 99bc2f5

Browse files
committed
Added Complete Command
1 parent e91bbdc commit 99bc2f5

File tree

8 files changed

+90
-4
lines changed

8 files changed

+90
-4
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ Docs for each command can be found at [`/docs`](docs/param.md)
2929

3030
They are automatically generated by Cobra.
3131

32+
## Command Completion
33+
34+
To enable shell completion, you can run:
35+
36+
param completion (bash|zsh)
37+
38+
To enable either `bash` or `zshell` completion
39+
3240
## TODO
3341

3442
- Set command - Command to set parameters

build/generate_docs.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build ignore
2+
13
package main
24

35
import (

cmd/completion.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package cmd
2+
3+
import (
4+
"os"
5+
6+
"github.com/spf13/cobra"
7+
)
8+
9+
var completionCmd = &cobra.Command{
10+
Use: "completion (bash|zsh)",
11+
Short: "Generates shell completion scripts",
12+
Long: `Output shell completion code for the specified shell (bash or zsh).
13+
The shell code must be evaluated to provide interactive completion of param commands.
14+
This can be done by sourcing it from ~/.bashrc
15+
16+
Examples:
17+
# Installing bash completion
18+
printf "
19+
# param shell completion
20+
source <(param completion bash)
21+
" >> $HOME/.bashrc
22+
source $HOME/.bashrc`,
23+
Args: cobra.OnlyValidArgs,
24+
ValidArgs: []string{"bash", "zsh"},
25+
Run: func(cmd *cobra.Command, args []string) {
26+
if args[0] == "bash" {
27+
RootCmd.GenBashCompletion(os.Stdout)
28+
} else if args[0] == "zsh" {
29+
RootCmd.GenZshCompletion(os.Stdout)
30+
}
31+
},
32+
}
33+
34+
func init() {
35+
RootCmd.AddCommand(completionCmd)
36+
}

docs/param.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ Param is a cli tool to improve interacting with AWS Parameter Store.
1616
### SEE ALSO
1717

1818
* [param add](param_add.md) - Add a paramter to Parameter Store.
19+
* [param completion](param_completion.md) - Generates shell completion scripts
1920
* [param copy](param_copy.md) - Copy a parameter to clipboard.
2021
* [param list](param_list.md) - List parameters in Parameter Store.
2122

22-
###### Auto generated by spf13/cobra on 1-Jul-2018
23+
###### Auto generated by spf13/cobra on 2-Jul-2018

docs/param_add.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ param add [flags]
2727

2828
* [param](param.md) - Tools to improve Parameter Store on the command line.
2929

30-
###### Auto generated by spf13/cobra on 1-Jul-2018
30+
###### Auto generated by spf13/cobra on 2-Jul-2018

docs/param_completion.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
## param completion
2+
3+
Generates shell completion scripts
4+
5+
### Synopsis
6+
7+
Output shell completion code for the specified shell (bash or zsh).
8+
The shell code must be evaluated to provide interactive completion of param commands.
9+
This can be done by sourcing it from ~/.bashrc
10+
11+
Examples:
12+
# Installing bash completion
13+
printf "
14+
# param shell completion
15+
source <(param completion bash)
16+
" >> $HOME/.bashrc
17+
source $HOME/.bashrc
18+
19+
```
20+
param completion (bash|zsh) [flags]
21+
```
22+
23+
### Options
24+
25+
```
26+
-h, --help help for completion
27+
```
28+
29+
### Options inherited from parent commands
30+
31+
```
32+
--config string config file (default is $HOME/.param.yaml)
33+
```
34+
35+
### SEE ALSO
36+
37+
* [param](param.md) - Tools to improve Parameter Store on the command line.
38+
39+
###### Auto generated by spf13/cobra on 2-Jul-2018

docs/param_copy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ param copy parameter_name [flags]
2727

2828
* [param](param.md) - Tools to improve Parameter Store on the command line.
2929

30-
###### Auto generated by spf13/cobra on 1-Jul-2018
30+
###### Auto generated by spf13/cobra on 2-Jul-2018

docs/param_list.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ param list [flags]
2828

2929
* [param](param.md) - Tools to improve Parameter Store on the command line.
3030

31-
###### Auto generated by spf13/cobra on 1-Jul-2018
31+
###### Auto generated by spf13/cobra on 2-Jul-2018

0 commit comments

Comments
 (0)