Skip to content

Commit

Permalink
Added flag definitions for kompose kubernetes#37
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher A. Baumbauer authored and rtnpro committed Nov 16, 2016
1 parent ff218c9 commit 6a4c1f9
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions cli/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ import (
// Hook for erroring and exit out on warning
type errorOnWarningHook struct{}

// array consisting of our common conversion flags that will get passed along
// for the autocomplete aspect
var (
commonConvertFlagsList = []string{"out", "replicas", "yaml", "stdout", "emptyvols"}
)

func (errorOnWarningHook) Levels() []logrus.Level {
return []logrus.Level{logrus.WarnLevel}
}
Expand Down Expand Up @@ -75,6 +81,17 @@ func ConvertCommandDummy() cli.Command {
return command
}

// Generate the Bash completion flag taking the common flags plus whatever is
// passed into the function to correspond to the primary command specific args
func generateBashCompletion(args []string) {
commonArgs := []string{"bundle", "file", "suppress-warnings", "verbose", "error-on-warning", "provider"}
flags := append(commonArgs, args...)

for _,f := range flags {
fmt.Printf("--%s\n", f)
}
}

// ConvertKubernetesCommand defines the kompose convert subcommand for Kubernetes provider
func ConvertKubernetesCommand() cli.Command {
command := cli.Command{
Expand All @@ -83,6 +100,10 @@ func ConvertKubernetesCommand() cli.Command {
Action: func(c *cli.Context) {
app.Convert(c)
},
BashComplete: func(c *cli.Context) {
flags := []string{"chart", "deployment", "daemonset", "replicationcontroller"}
generateBashCompletion(append(flags, commonConvertFlagsList...))
},
Flags: []cli.Flag{
cli.BoolFlag{
Name: "chart,c",
Expand Down Expand Up @@ -114,6 +135,10 @@ func ConvertOpenShiftCommand() cli.Command {
Action: func(c *cli.Context) {
app.Convert(c)
},
BashComplete: func(c *cli.Context) {
flags := []string{"deploymentconfig"}
generateBashCompletion(append(flags, commonConvertFlagsList...))
},
Flags: []cli.Flag{
cli.BoolFlag{
Name: "deploymentconfig,dc",
Expand Down Expand Up @@ -160,6 +185,10 @@ func UpCommand() cli.Command {
Action: func(c *cli.Context) {
app.Up(c)
},
BashComplete: func(c *cli.Context) {
flags := []string{"emptyvols"}
generateBashCompletion(flags)
},
Flags: []cli.Flag{
cli.BoolFlag{
Name: "emptyvols",
Expand All @@ -177,6 +206,10 @@ func DownCommand() cli.Command {
Action: func(c *cli.Context) {
app.Down(c)
},
BashComplete: func(c *cli.Context) {
flags := []string{"emptyvols"}
generateBashCompletion(flags)
},
Flags: []cli.Flag{
cli.BoolFlag{
Name: "emptyvols",
Expand Down

0 comments on commit 6a4c1f9

Please sign in to comment.