Skip to content

Commit

Permalink
Merge pull request #702 from gocardless/benwh/no-init-empty-file
Browse files Browse the repository at this point in the history
Prevent stolonctl init with empty file
  • Loading branch information
sgotti authored Oct 8, 2019
2 parents cd21db4 + 5bd0ef2 commit 182e091
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions cmd/stolonctl/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,15 @@ func initCluster(cmd *cobra.Command, args []string) {
die("too many arguments")
}

dataSupplied := false
data := []byte{}
switch len(args) {
case 1:
dataSupplied = true
data = []byte(args[0])
case 0:
if initOpts.file != "" {
dataSupplied = true
var err error
if initOpts.file == "-" {
data, err = ioutil.ReadAll(os.Stdin)
Expand Down Expand Up @@ -104,14 +107,14 @@ func initCluster(cmd *cobra.Command, args []string) {
}

var cs *cluster.ClusterSpec
if len(data) == 0 {
// Define a new cluster spec with initMode "new"
cs = &cluster.ClusterSpec{}
cs.InitMode = cluster.ClusterInitModeP(cluster.ClusterInitModeNew)
} else {
if dataSupplied {
if err := json.Unmarshal(data, &cs); err != nil {
die("failed to unmarshal cluster spec: %v", err)
}
} else {
// Define a new cluster spec with initMode "new"
cs = &cluster.ClusterSpec{}
cs.InitMode = cluster.ClusterInitModeP(cluster.ClusterInitModeNew)
}

if err := cs.Validate(); err != nil {
Expand Down

0 comments on commit 182e091

Please sign in to comment.