Skip to content

Commit a9f280d

Browse files
committed
Extract a shared context command
1 parent 6e42a16 commit a9f280d

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

‎pkg/cmd/context.go‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package cmd
2+
3+
import "github.com/spf13/cobra"
4+
5+
type ContextConfig struct {
6+
ValidArgsFunction cobra.CompletionFunc
7+
Example string
8+
RunE func(cmd *cobra.Command, args []string) error
9+
Short, Long string
10+
}
11+
12+
func NewContextCmd(c *ContextConfig) *cobra.Command {
13+
if c.Short == "" {
14+
c.Short = "Manage contexts"
15+
}
16+
if c.Long == "" {
17+
c.Long = "context defines the backend to talks to. You can switch back and forth with \"-\" as a shortcut to the last used context."
18+
}
19+
if c.Example == "" {
20+
c.Example = "Please refer to the documentation for examples on how to use contexts."
21+
}
22+
23+
contextCmd := &cobra.Command{
24+
Use: "context <name>",
25+
Aliases: []string{"ctx"},
26+
Short: c.Short,
27+
Long: c.Long,
28+
ValidArgsFunction: c.ValidArgsFunction,
29+
Example: c.Example,
30+
RunE: c.RunE,
31+
}
32+
33+
return contextCmd
34+
}

0 commit comments

Comments
 (0)