Skip to content

Commit 42ae480

Browse files
committed
allow for optional custom zero values for defaultFlags and add config-id
1 parent 97d0e47 commit 42ae480

File tree

7 files changed

+15
-10
lines changed

7 files changed

+15
-10
lines changed

cmd/cloudNetworkVipCreate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,6 @@ func init() {
9494
cloudNetworkVipCmd.AddCommand(cloudNetworkVipCreateCmd)
9595
cloudNetworkVipCreateCmd.Flags().String("name", fmt.Sprintf("vip-%s", utils.RandomString(8)),
9696
"name for the new VIP")
97-
cloudNetworkVipCreateCmd.Flags().Int64("zone", cast.ToInt64(defaultFlag("zone")),
97+
cloudNetworkVipCreateCmd.Flags().Int64("zone", cast.ToInt64(defaultFlag("zone", -1)),
9898
"zone id to create VIP in (see: 'cloud server options --zones')")
9999
}

cmd/cloudPrivateParentCreate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func init() {
7272

7373
cloudPrivateParentCreateCmd.Flags().Int64("config-id", -1, "config-id (category must be bare-metal or bare-metal-r)")
7474
cloudPrivateParentCreateCmd.Flags().String("name", "", "name for your Private Parent")
75-
cloudPrivateParentCreateCmd.Flags().Int64("zone", cast.ToInt64(defaultFlag("zone")),
75+
cloudPrivateParentCreateCmd.Flags().Int64("zone", cast.ToInt64(defaultFlag("zone", -1)),
7676
"id number of the zone to provision the Private Parent in ('cloud server options --zones')")
7777

7878
reqs := []string{"config-id", "name"}

cmd/cloudServerClone.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package cmd
1818
import (
1919
"fmt"
2020

21+
"github.com/spf13/cast"
2122
"github.com/spf13/cobra"
2223

2324
"github.com/liquidweb/liquidweb-cli/types/api"
@@ -162,7 +163,7 @@ func init() {
162163
cloudServerCloneCmd.Flags().Int64("vcpu", -1, "amount of vcpus for new Cloud Server (when private-parent)")
163164

164165
// Non Private Parent
165-
cloudServerCloneCmd.Flags().Int64("config-id", -1,
166+
cloudServerCloneCmd.Flags().Int64("config-id", cast.ToInt64(defaultFlag("config-id", -1)),
166167
"config-id for new Cloud Server (when !private-parent) (see: 'cloud server options --configs')")
167168

168169
if err := cloudServerCloneCmd.MarkFlagRequired("uniq-id"); err != nil {

cmd/cloudServerCreate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ func init() {
140140
cloudServerCreateCmd.Flags().Int("ips", 1, "amount of IP addresses")
141141
cloudServerCreateCmd.Flags().String("public-ssh-key", sshPubKeyFile,
142142
"path to file containing the public ssh key you wish to be on the new Cloud Server")
143-
cloudServerCreateCmd.Flags().Int("config-id", 0, "config-id to use")
143+
cloudServerCreateCmd.Flags().Int("config-id", cast.ToInt(defaultFlag("config-id", -1)), "config-id to use")
144144
cloudServerCreateCmd.Flags().Int("backup-days", -1, "Enable daily backup plan. This is the amount of days to keep a backup")
145145
cloudServerCreateCmd.Flags().Int("backup-quota", -1, "Enable quota backup plan. This is the total amount of GB to keep.")
146146
cloudServerCreateCmd.Flags().String("bandwidth", "SS.10000", "bandwidth package to use")
147-
cloudServerCreateCmd.Flags().Int64("zone", cast.ToInt64(defaultFlag("zone")), "zone (id) to create new Cloud Server in (see 'cloud server options --zones')")
147+
cloudServerCreateCmd.Flags().Int64("zone", cast.ToInt64(defaultFlag("zone", -1)), "zone (id) to create new Cloud Server in (see 'cloud server options --zones')")
148148
cloudServerCreateCmd.Flags().String("password", "", "root or administrator password to set")
149149

150150
cloudServerCreateCmd.Flags().Int("backup-id", -1, "id of cloud backup to create from (see 'cloud backup list')")

cmd/networkIpPoolCreate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ your account.`,
3737
zoneFlag, _ := cmd.Flags().GetInt64("zone")
3838
newIpsFlag, _ := cmd.Flags().GetInt64("new-ips")
3939

40-
if len(networkIpPoolCreateCmdAddIpsFlag) == 0 && newIpsFlag == -1 || zoneFlag == 0 {
40+
if len(networkIpPoolCreateCmdAddIpsFlag) == 0 && newIpsFlag == -1 || zoneFlag == -1 {
4141
lwCliInst.Die(fmt.Errorf("flags --new-ips --add-ips cannot both be empty. --zone cannot be empty"))
4242
}
4343

@@ -66,6 +66,6 @@ func init() {
6666
networkIpPoolCreateCmd.Flags().StringSliceVar(&networkIpPoolCreateCmdAddIpsFlag, "add-ips", []string{},
6767
"ips separated by ',' to add to created IP Pool")
6868
networkIpPoolCreateCmd.Flags().Int64("new-ips", -1, "amount of IPs to assign to the created IP Pool")
69-
networkIpPoolCreateCmd.Flags().Int64("zone", cast.ToInt64(defaultFlag("zone")),
69+
networkIpPoolCreateCmd.Flags().Int64("zone", cast.ToInt64(defaultFlag("zone", -1)),
7070
"zone id to create the IP Pool in")
7171
}

cmd/root.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,14 @@ func osArgsForContext(re *regexp.Regexp) {
101101
}
102102
}
103103

104-
func defaultFlag(flag string) (value interface{}) {
104+
func defaultFlag(flag string, defaultValueList ...interface{}) (value interface{}) {
105105
// calling config.InitConfig() here so default context gets set
106106
_, _ = config.InitConfig()
107107
setConfigArgs()
108108
value = defaults.GetOrNag(flag)
109+
if len(defaultValueList) > 0 && value == nil {
110+
value = defaultValueList[0]
111+
}
109112
return
110113
}
111114

flags/defaults/types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func (self AllFlags) String() string {
2525
}
2626

2727
var permittedFlags = map[string]bool{
28-
"zone": true,
29-
"template": true,
28+
"zone": true,
29+
"template": true,
30+
"config-id": true,
3031
}

0 commit comments

Comments
 (0)