Skip to content

Commit 8d36a22

Browse files
refine shell completion command
Signed-off-by: puneeth_aditya_5656 <myakampuneeth@gmail.com>
1 parent 8957bc6 commit 8d36a22

3 files changed

Lines changed: 23 additions & 9 deletions

File tree

cmd/completion.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
package cmd
1717

1818
import (
19-
"fmt"
20-
2119
"github.com/microcks/microcks-cli/pkg/errors"
2220
"github.com/spf13/cobra"
2321
)
@@ -27,7 +25,13 @@ func NewCompletionCommand() *cobra.Command {
2725
Use: "completion [bash|zsh|fish|powershell]",
2826
Short: "Generate shell completion scripts",
2927
Long: `Generate shell completion scripts`,
30-
Args: cobra.ExactArgs(1),
28+
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
29+
ValidArgs: []string{
30+
"bash",
31+
"zsh",
32+
"fish",
33+
"powershell",
34+
},
3135
Run: func(cmd *cobra.Command, args []string) {
3236
rootCmd := cmd.Root()
3337
var err error
@@ -41,8 +45,6 @@ func NewCompletionCommand() *cobra.Command {
4145
err = rootCmd.GenFishCompletion(cmd.OutOrStdout(), true)
4246
case "powershell":
4347
err = rootCmd.GenPowerShellCompletion(cmd.OutOrStdout())
44-
default:
45-
err = fmt.Errorf("unsupported shell %q", args[0])
4648
}
4749
errors.CheckError(err)
4850
},

cmd/completion_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,16 @@ func TestCompletionCommandGeneratesBash(t *testing.T) {
3636
assert.NoError(t, err)
3737
assert.Contains(t, buf.String(), "completion for microcks")
3838
}
39+
40+
func TestCompletionCommandRejectsUnsupportedShell(t *testing.T) {
41+
cmd := NewCommad()
42+
buf := &bytes.Buffer{}
43+
cmd.SetOut(buf)
44+
cmd.SetErr(buf)
45+
cmd.SetArgs([]string{"completion", "nushell"})
46+
47+
err := cmd.Execute()
48+
49+
assert.Error(t, err)
50+
assert.Contains(t, err.Error(), "invalid argument")
51+
}

documentation/cmd/completion.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
## `microcks completion` - Generate shell completion scripts
2-
3-
Generates shell completion scripts for supported shells.
1+
## `microcks completion` – Generate Shell Completion Scripts
2+
Generates shell completion scripts for bash, zsh, fish, and PowerShell.
43

54
### Usage
65
```bash
76
microcks completion [bash|zsh|fish|powershell]
87
```
98

10-
### Examples
9+
### Example
1110
```bash
1211
# Generate bash completion
1312
microcks completion bash

0 commit comments

Comments
 (0)