Skip to content

Commit fc9314f

Browse files
committed
Merge branch 'master' into secondary-ipv6
2 parents 30ff94a + 473ed8c commit fc9314f

25 files changed

+919
-81
lines changed

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@ Usage:
2222
lw [command]
2323
2424
Available Commands:
25-
asset All things assets
26-
auth authentication actions
27-
cloud Interact with LiquidWeb's Cloud platform
28-
completion Generate completion script
29-
dedicated All things dedicated server
30-
help Help about any command
31-
network network actions
32-
plan Process YAML plan file
33-
ssh SSH to a Server
34-
version show build information
25+
asset All things assets
26+
auth authentication actions
27+
cloud Interact with LiquidWeb's Cloud platform
28+
completion Generate completion script
29+
dedicated All things dedicated server
30+
default-flags Manage default flags
31+
help Help about any command
32+
network network actions
33+
plan Process YAML plan file
34+
ssh SSH to a Server
35+
version show build information
3536
3637
Flags:
3738
--config string config file (default is $HOME/.liquidweb-cli.yaml)

cmd/cloudNetworkVipCreate.go

Lines changed: 2 additions & 5 deletions
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"
@@ -93,10 +94,6 @@ func init() {
9394
cloudNetworkVipCmd.AddCommand(cloudNetworkVipCreateCmd)
9495
cloudNetworkVipCreateCmd.Flags().String("name", fmt.Sprintf("vip-%s", utils.RandomString(8)),
9596
"name for the new VIP")
96-
cloudNetworkVipCreateCmd.Flags().Int64("zone", -1,
97+
cloudNetworkVipCreateCmd.Flags().Int64("zone", cast.ToInt64(defaultFlag("cloud_network_vip_create_zone", -1)),
9798
"zone id to create VIP in (see: 'cloud server options --zones')")
98-
99-
if err := cloudNetworkVipCreateCmd.MarkFlagRequired("zone"); err != nil {
100-
lwCliInst.Die(err)
101-
}
10299
}

cmd/cloudPrivateParentCreate.go

Lines changed: 9 additions & 10 deletions
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"
@@ -69,17 +70,15 @@ of configs, check 'cloud server options --configs'.`,
6970
func init() {
7071
cloudPrivateParentCmd.AddCommand(cloudPrivateParentCreateCmd)
7172

72-
cloudPrivateParentCreateCmd.Flags().Int64("config-id", -1, "config-id (category must be bare-metal or bare-metal-r)")
73+
cloudPrivateParentCreateCmd.Flags().Int64("config-id", cast.ToInt64(defaultFlag("cloud_private-parent_create_config-id", -1)), "config-id (category must be bare-metal or bare-metal-r)")
7374
cloudPrivateParentCreateCmd.Flags().String("name", "", "name for your Private Parent")
74-
cloudPrivateParentCreateCmd.Flags().Int64("zone", -1, "id number of the zone to provision the Private Parent in ('cloud server options --zones')")
75+
cloudPrivateParentCreateCmd.Flags().Int64("zone", cast.ToInt64(defaultFlag("cloud_private-parent_create_zone", -1)),
76+
"id number of the zone to provision the Private Parent in ('cloud server options --zones')")
7577

76-
if err := cloudPrivateParentCreateCmd.MarkFlagRequired("config-id"); err != nil {
77-
lwCliInst.Die(err)
78-
}
79-
if err := cloudPrivateParentCreateCmd.MarkFlagRequired("zone"); err != nil {
80-
lwCliInst.Die(err)
81-
}
82-
if err := cloudPrivateParentCreateCmd.MarkFlagRequired("name"); err != nil {
83-
lwCliInst.Die(err)
78+
reqs := []string{"name"}
79+
for _, req := range reqs {
80+
if err := cloudPrivateParentCreateCmd.MarkFlagRequired(req); err != nil {
81+
lwCliInst.Die(err)
82+
}
8483
}
8584
}

cmd/cloudServerClone.go

Lines changed: 3 additions & 5 deletions
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"
@@ -66,9 +67,6 @@ Server is not on a Private Parent.`,
6667
hostnameFlag: map[string]string{"type": "NonEmptyString", "optional": "false"},
6768
}
6869

69-
if privateParentFlag != "" && configIdFlag != -1 {
70-
lwCliInst.Die(fmt.Errorf("cant pass both --config-id and --private-parent flags"))
71-
}
7270
if privateParentFlag == "" && configIdFlag == -1 {
7371
lwCliInst.Die(fmt.Errorf("must pass --config-id or --private-parent"))
7472
}
@@ -117,7 +115,7 @@ Server is not on a Private Parent.`,
117115
cloneArgs["vcpu"] = vcpuFlag
118116
validateFields[vcpuFlag] = "PositiveInt64"
119117
}
120-
if configIdFlag != -1 {
118+
if configIdFlag != -1 && privateParentFlag == "" {
121119
cloneArgs["config_id"] = configIdFlag
122120
validateFields[configIdFlag] = "PositiveInt64"
123121
}
@@ -174,7 +172,7 @@ func init() {
174172
cloudServerCloneCmd.Flags().Int64("vcpu", -1, "amount of vcpus for new Cloud Server (when private-parent)")
175173

176174
// Non Private Parent
177-
cloudServerCloneCmd.Flags().Int64("config-id", -1,
175+
cloudServerCloneCmd.Flags().Int64("config-id", cast.ToInt64(defaultFlag("cloud_server_clone_config-id", -1)),
178176
"config-id for new Cloud Server (when !private-parent) (see: 'cloud server options --configs')")
179177

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

cmd/cloudServerCreate.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,18 +141,18 @@ func init() {
141141
sshPubKeyFile = fmt.Sprintf("%s/.ssh/id_rsa.pub", home)
142142
}
143143

144-
cloudServerCreateCmd.Flags().String("template", "", "template to use (see 'cloud server options --templates')")
144+
cloudServerCreateCmd.Flags().String("template", cast.ToString(defaultFlag("cloud_server_create_template")), "template to use (see 'cloud server options --templates')")
145145
cloudServerCreateCmd.Flags().String("type", "SS.VPS", "some examples of types; SS.VPS, SS.VPS.WIN, SS.VM, SS.VM.WIN")
146146
cloudServerCreateCmd.Flags().String("hostname", "", "hostname to set")
147147
cloudServerCreateCmd.Flags().Int("ips", 1, "amount of IPv4 addresses")
148148
cloudServerCreateCmd.Flags().Int("ip6s", 0, "amount of IPv6 /64s")
149149
cloudServerCreateCmd.Flags().String("public-ssh-key", sshPubKeyFile,
150150
"path to file containing the public ssh key you wish to be on the new Cloud Server")
151-
cloudServerCreateCmd.Flags().Int("config-id", 0, "config-id to use")
151+
cloudServerCreateCmd.Flags().Int("config-id", cast.ToInt(defaultFlag("cloud_server_create_config-id", -1)), "config-id to use")
152152
cloudServerCreateCmd.Flags().Int("backup-days", -1, "Enable daily backup plan. This is the amount of days to keep a backup")
153153
cloudServerCreateCmd.Flags().Int("backup-quota", -1, "Enable quota backup plan. This is the total amount of GB to keep.")
154154
cloudServerCreateCmd.Flags().String("bandwidth", "SS.10000", "bandwidth package to use")
155-
cloudServerCreateCmd.Flags().Int64("zone", 0, "zone (id) to create new Cloud Server in (see 'cloud server options --zones')")
155+
cloudServerCreateCmd.Flags().Int64("zone", cast.ToInt64(defaultFlag("cloud_server_create_zone", -1)), "zone (id) to create new Cloud Server in (see 'cloud server options --zones')")
156156
cloudServerCreateCmd.Flags().String("password", "", "root or administrator password to set")
157157

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

cmd/cloudServerResize.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/instance"
@@ -104,7 +105,7 @@ func init() {
104105
cloudServerResizeCmd.Flags().Int64("memory", -1, "desired memory (when private-parent)")
105106
cloudServerResizeCmd.Flags().Bool("skip-fs-resize", false, "whether or not to skip the fs resize")
106107
cloudServerResizeCmd.Flags().Int64("vcpu", -1, "desired vcpu count (when private-parent)")
107-
cloudServerResizeCmd.Flags().Int64("config-id", -1,
108+
cloudServerResizeCmd.Flags().Int64("config-id", cast.ToInt64(defaultFlag("cloud_server_resize_config-id", -1)),
108109
"config-id of your desired config (when !private-parent) (see 'cloud server options --configs')")
109110

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

cmd/cloudTemplateRestore.go

Lines changed: 2 additions & 4 deletions
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/instance"
@@ -59,12 +60,9 @@ func init() {
5960
cloudTemplateCmd.AddCommand(cloudTemplateRestoreCmd)
6061

6162
cloudTemplateRestoreCmd.Flags().String("uniq-id", "", "uniq-id of Cloud Server")
62-
cloudTemplateRestoreCmd.Flags().String("template", "", "name of template to restore")
63+
cloudTemplateRestoreCmd.Flags().String("template", cast.ToString(defaultFlag("cloud_template_restore_template")), "name of template to restore")
6364

6465
if err := cloudTemplateRestoreCmd.MarkFlagRequired("uniq-id"); err != nil {
6566
lwCliInst.Die(err)
6667
}
67-
if err := cloudTemplateRestoreCmd.MarkFlagRequired("template"); err != nil {
68-
lwCliInst.Die(err)
69-
}
7068
}

cmd/defaultFlags.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
Copyright © LiquidWeb
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
package cmd
17+
18+
import (
19+
"os"
20+
21+
"github.com/spf13/cobra"
22+
)
23+
24+
var defaultFlagsCmd = &cobra.Command{
25+
Use: "default-flags",
26+
Short: "Manage default flags",
27+
Long: `Manage the configured default flags.
28+
29+
If a default flag is set (such as for "zone") then any subcommand will use its
30+
value in place if omitted. Default flags are auth context aware. For details
31+
on auth contexts, see 'help auth'.
32+
33+
For a full list of capabilities, please refer to the "Available Commands" section.`,
34+
Run: func(cmd *cobra.Command, args []string) {
35+
if err := cmd.Help(); err != nil {
36+
lwCliInst.Die(err)
37+
}
38+
os.Exit(1)
39+
},
40+
}
41+
42+
func init() {
43+
rootCmd.AddCommand(defaultFlagsCmd)
44+
}

cmd/defaultFlagsDelete.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
Copyright © 2019 LiquidWeb
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
package cmd
17+
18+
import (
19+
"fmt"
20+
21+
"github.com/spf13/cobra"
22+
23+
"github.com/liquidweb/liquidweb-cli/flags/defaults"
24+
)
25+
26+
var defaultFlagsDeleteCmd = &cobra.Command{
27+
Use: "delete",
28+
Short: "Delete a flag",
29+
Long: `Delete a flag for the current context.
30+
31+
When a default flag is set (such as "zone") then any subcommand will use its
32+
value in place if omitted. Default flags are auth context aware. For details
33+
on auth contexts, see 'help auth'.`,
34+
Run: func(cmd *cobra.Command, args []string) {
35+
flagName, _ := cmd.Flags().GetString("flag")
36+
37+
if err := defaults.Delete(flagName); err != nil {
38+
lwCliInst.Die(err)
39+
}
40+
41+
fmt.Printf("deleted default flag [%s]\n", flagName)
42+
},
43+
}
44+
45+
func init() {
46+
defaultFlagsCmd.AddCommand(defaultFlagsDeleteCmd)
47+
defaultFlagsDeleteCmd.Flags().String("flag", "", "name of the flag to delete")
48+
if err := defaultFlagsDeleteCmd.MarkFlagRequired("flag"); err != nil {
49+
lwCliInst.Die(err)
50+
}
51+
}

cmd/defaultFlagsGet.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
Copyright © 2019 LiquidWeb
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
package cmd
17+
18+
import (
19+
"fmt"
20+
21+
"github.com/spf13/cobra"
22+
23+
"github.com/liquidweb/liquidweb-cli/flags/defaults"
24+
)
25+
26+
var defaultFlagsGetCmd = &cobra.Command{
27+
Use: "get",
28+
Short: "Get details on a flag",
29+
Long: `Get details on a flag in the current context.
30+
31+
When a default flag is set (such as "zone") then any subcommand will use its
32+
value in place if omitted. Default flags are auth context aware. For details
33+
on auth contexts, see 'help auth'.`,
34+
Run: func(cmd *cobra.Command, args []string) {
35+
flagName, _ := cmd.Flags().GetString("flag")
36+
37+
value, err := defaults.Get(flagName)
38+
if err != nil {
39+
lwCliInst.Die(err)
40+
}
41+
42+
fmt.Printf("flag: %s\n", flagName)
43+
fmt.Printf("\tvalue: %+v\n", value)
44+
},
45+
}
46+
47+
func init() {
48+
defaultFlagsCmd.AddCommand(defaultFlagsGetCmd)
49+
defaultFlagsGetCmd.Flags().String("flag", "", "name of the flag")
50+
if err := defaultFlagsGetCmd.MarkFlagRequired("flag"); err != nil {
51+
lwCliInst.Die(err)
52+
}
53+
}

0 commit comments

Comments
 (0)