Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added flag definitions for kompose #37 #279

Merged
merged 1 commit into from
Nov 14, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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