Skip to content

Commit

Permalink
Add an option for cluster file descriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
sagikazarmark committed Jan 20, 2019
1 parent 9676590 commit 6620b40
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions internal/cli/command/cluster/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
)

type createOptions struct {
file string
}

// NewCreateCommand creates a new cobra.Command for `banzai cluster create`.
Expand All @@ -51,6 +52,10 @@ func NewCreateCommand(banzaiCli cli.Cli) *cobra.Command {
},
}

flags := cmd.Flags()

flags.StringVarP(&options.file, "file", "f", "", "Cluster descriptor file")

return cmd
}

Expand All @@ -61,24 +66,29 @@ func runCreate(banzaiCli cli.Cli, options createOptions) {

if isInteractive() {
var content string
var fileName = options.file

for {
fileName := ""
_ = survey.AskOne(
&survey.Input{
Message: "Load a JSON or YAML file:",
Default: "skip",
Help: "Give either a relative or an absolute path to a file containing a JSON or YAML Cluster creation request. Leave empty to cancel.",
},
&fileName,
nil,
)
if fileName == "skip" || fileName == "" {
break
if fileName == "" {
_ = survey.AskOne(
&survey.Input{
Message: "Load a JSON or YAML file:",
Default: "skip",
Help: "Give either a relative or an absolute path to a file containing a JSON or YAML Cluster creation request. Leave empty to cancel.",
},
&fileName,
nil,
)
if fileName == "skip" || fileName == "" {
break
}
}

if raw, err := ioutil.ReadFile(fileName); err != nil {
fileName = "" // reset fileName so that we can ask for one

log.Errorf("failed to read file %q: %v", fileName, err)

continue
} else {
if err := unmarshal(raw, &out); err != nil {
Expand Down Expand Up @@ -193,7 +203,7 @@ func runCreate(banzaiCli cli.Cli, options createOptions) {

log.Info("cluster is being created")
log.Infof("you can check its status with the command `banzai cluster get %q`", out.Name)
Out1(cluster, []string{"ID", "Name"})
Out1(cluster, []string{"Id", "Name"})
}

func validateClusterCreateRequest(val interface{}) error {
Expand Down

0 comments on commit 6620b40

Please sign in to comment.