Skip to content
Merged
Show file tree
Hide file tree
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
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@ Usage:
lw [command]

Available Commands:
asset All things assets
auth authentication actions
cloud Interact with LiquidWeb's Cloud platform
completion Generate completion script
dedicated All things dedicated server
help Help about any command
network network actions
plan Process YAML plan file
ssh SSH to a Server
version show build information
asset All things assets
auth authentication actions
cloud Interact with LiquidWeb's Cloud platform
completion Generate completion script
dedicated All things dedicated server
default-flags Manage default flags
help Help about any command
network network actions
plan Process YAML plan file
ssh SSH to a Server
version show build information

Flags:
--config string config file (default is $HOME/.liquidweb-cli.yaml)
Expand Down
7 changes: 2 additions & 5 deletions cmd/cloudNetworkVipCreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cmd
import (
"fmt"

"github.com/spf13/cast"
"github.com/spf13/cobra"

"github.com/liquidweb/liquidweb-cli/types/api"
Expand Down Expand Up @@ -93,10 +94,6 @@ func init() {
cloudNetworkVipCmd.AddCommand(cloudNetworkVipCreateCmd)
cloudNetworkVipCreateCmd.Flags().String("name", fmt.Sprintf("vip-%s", utils.RandomString(8)),
"name for the new VIP")
cloudNetworkVipCreateCmd.Flags().Int64("zone", -1,
cloudNetworkVipCreateCmd.Flags().Int64("zone", cast.ToInt64(defaultFlag("cloud_network_vip_create_zone", -1)),
"zone id to create VIP in (see: 'cloud server options --zones')")

if err := cloudNetworkVipCreateCmd.MarkFlagRequired("zone"); err != nil {
lwCliInst.Die(err)
}
}
19 changes: 9 additions & 10 deletions cmd/cloudPrivateParentCreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cmd
import (
"fmt"

"github.com/spf13/cast"
"github.com/spf13/cobra"

"github.com/liquidweb/liquidweb-cli/types/api"
Expand Down Expand Up @@ -69,17 +70,15 @@ of configs, check 'cloud server options --configs'.`,
func init() {
cloudPrivateParentCmd.AddCommand(cloudPrivateParentCreateCmd)

cloudPrivateParentCreateCmd.Flags().Int64("config-id", -1, "config-id (category must be bare-metal or bare-metal-r)")
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)")
cloudPrivateParentCreateCmd.Flags().String("name", "", "name for your Private Parent")
cloudPrivateParentCreateCmd.Flags().Int64("zone", -1, "id number of the zone to provision the Private Parent in ('cloud server options --zones')")
cloudPrivateParentCreateCmd.Flags().Int64("zone", cast.ToInt64(defaultFlag("cloud_private-parent_create_zone", -1)),
"id number of the zone to provision the Private Parent in ('cloud server options --zones')")

if err := cloudPrivateParentCreateCmd.MarkFlagRequired("config-id"); err != nil {
lwCliInst.Die(err)
}
if err := cloudPrivateParentCreateCmd.MarkFlagRequired("zone"); err != nil {
lwCliInst.Die(err)
}
if err := cloudPrivateParentCreateCmd.MarkFlagRequired("name"); err != nil {
lwCliInst.Die(err)
reqs := []string{"name"}
for _, req := range reqs {
if err := cloudPrivateParentCreateCmd.MarkFlagRequired(req); err != nil {
lwCliInst.Die(err)
}
}
}
8 changes: 3 additions & 5 deletions cmd/cloudServerClone.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cmd
import (
"fmt"

"github.com/spf13/cast"
"github.com/spf13/cobra"

"github.com/liquidweb/liquidweb-cli/types/api"
Expand Down Expand Up @@ -64,9 +65,6 @@ Server is not on a Private Parent.`,
hostnameFlag: map[string]string{"type": "NonEmptyString", "optional": "false"},
}

if privateParentFlag != "" && configIdFlag != -1 {
lwCliInst.Die(fmt.Errorf("cant pass both --config-id and --private-parent flags"))
}
if privateParentFlag == "" && configIdFlag == -1 {
lwCliInst.Die(fmt.Errorf("must pass --config-id or --private-parent"))
}
Expand Down Expand Up @@ -114,7 +112,7 @@ Server is not on a Private Parent.`,
cloneArgs["vcpu"] = vcpuFlag
validateFields[vcpuFlag] = "PositiveInt64"
}
if configIdFlag != -1 {
if configIdFlag != -1 && privateParentFlag == "" {
cloneArgs["config_id"] = configIdFlag
validateFields[configIdFlag] = "PositiveInt64"
}
Expand Down Expand Up @@ -162,7 +160,7 @@ func init() {
cloudServerCloneCmd.Flags().Int64("vcpu", -1, "amount of vcpus for new Cloud Server (when private-parent)")

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

if err := cloudServerCloneCmd.MarkFlagRequired("uniq-id"); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions cmd/cloudServerCreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,17 @@ func init() {
sshPubKeyFile = fmt.Sprintf("%s/.ssh/id_rsa.pub", home)
}

cloudServerCreateCmd.Flags().String("template", "", "template to use (see 'cloud server options --templates')")
cloudServerCreateCmd.Flags().String("template", cast.ToString(defaultFlag("cloud_server_create_template")), "template to use (see 'cloud server options --templates')")
cloudServerCreateCmd.Flags().String("type", "SS.VPS", "some examples of types; SS.VPS, SS.VPS.WIN, SS.VM, SS.VM.WIN")
cloudServerCreateCmd.Flags().String("hostname", "", "hostname to set")
cloudServerCreateCmd.Flags().Int("ips", 1, "amount of IP addresses")
cloudServerCreateCmd.Flags().String("public-ssh-key", sshPubKeyFile,
"path to file containing the public ssh key you wish to be on the new Cloud Server")
cloudServerCreateCmd.Flags().Int("config-id", 0, "config-id to use")
cloudServerCreateCmd.Flags().Int("config-id", cast.ToInt(defaultFlag("cloud_server_create_config-id", -1)), "config-id to use")
cloudServerCreateCmd.Flags().Int("backup-days", -1, "Enable daily backup plan. This is the amount of days to keep a backup")
cloudServerCreateCmd.Flags().Int("backup-quota", -1, "Enable quota backup plan. This is the total amount of GB to keep.")
cloudServerCreateCmd.Flags().String("bandwidth", "SS.10000", "bandwidth package to use")
cloudServerCreateCmd.Flags().Int64("zone", 0, "zone (id) to create new Cloud Server in (see 'cloud server options --zones')")
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')")
cloudServerCreateCmd.Flags().String("password", "", "root or administrator password to set")

cloudServerCreateCmd.Flags().Int("backup-id", -1, "id of cloud backup to create from (see 'cloud backup list')")
Expand Down
3 changes: 2 additions & 1 deletion cmd/cloudServerResize.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cmd
import (
"fmt"

"github.com/spf13/cast"
"github.com/spf13/cobra"

"github.com/liquidweb/liquidweb-cli/instance"
Expand Down Expand Up @@ -104,7 +105,7 @@ func init() {
cloudServerResizeCmd.Flags().Int64("memory", -1, "desired memory (when private-parent)")
cloudServerResizeCmd.Flags().Bool("skip-fs-resize", false, "whether or not to skip the fs resize")
cloudServerResizeCmd.Flags().Int64("vcpu", -1, "desired vcpu count (when private-parent)")
cloudServerResizeCmd.Flags().Int64("config-id", -1,
cloudServerResizeCmd.Flags().Int64("config-id", cast.ToInt64(defaultFlag("cloud_server_resize_config-id", -1)),
"config-id of your desired config (when !private-parent) (see 'cloud server options --configs')")

if err := cloudServerResizeCmd.MarkFlagRequired("uniq-id"); err != nil {
Expand Down
6 changes: 2 additions & 4 deletions cmd/cloudTemplateRestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cmd
import (
"fmt"

"github.com/spf13/cast"
"github.com/spf13/cobra"

"github.com/liquidweb/liquidweb-cli/instance"
Expand Down Expand Up @@ -59,12 +60,9 @@ func init() {
cloudTemplateCmd.AddCommand(cloudTemplateRestoreCmd)

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

if err := cloudTemplateRestoreCmd.MarkFlagRequired("uniq-id"); err != nil {
lwCliInst.Die(err)
}
if err := cloudTemplateRestoreCmd.MarkFlagRequired("template"); err != nil {
lwCliInst.Die(err)
}
}
44 changes: 44 additions & 0 deletions cmd/defaultFlags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Copyright © LiquidWeb

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
"os"

"github.com/spf13/cobra"
)

var defaultFlagsCmd = &cobra.Command{
Use: "default-flags",
Short: "Manage default flags",
Long: `Manage the configured default flags.

If a default flag is set (such as for "zone") then any subcommand will use its
value in place if omitted. Default flags are auth context aware. For details
on auth contexts, see 'help auth'.

For a full list of capabilities, please refer to the "Available Commands" section.`,
Run: func(cmd *cobra.Command, args []string) {
if err := cmd.Help(); err != nil {
lwCliInst.Die(err)
}
os.Exit(1)
},
}

func init() {
rootCmd.AddCommand(defaultFlagsCmd)
}
51 changes: 51 additions & 0 deletions cmd/defaultFlagsDelete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Copyright © 2019 LiquidWeb

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
"fmt"

"github.com/spf13/cobra"

"github.com/liquidweb/liquidweb-cli/flags/defaults"
)

var defaultFlagsDeleteCmd = &cobra.Command{
Use: "delete",
Short: "Delete a flag",
Long: `Delete a flag for the current context.

When a default flag is set (such as "zone") then any subcommand will use its
value in place if omitted. Default flags are auth context aware. For details
on auth contexts, see 'help auth'.`,
Run: func(cmd *cobra.Command, args []string) {
flagName, _ := cmd.Flags().GetString("flag")

if err := defaults.Delete(flagName); err != nil {
lwCliInst.Die(err)
}

fmt.Printf("deleted default flag [%s]\n", flagName)
},
}

func init() {
defaultFlagsCmd.AddCommand(defaultFlagsDeleteCmd)
defaultFlagsDeleteCmd.Flags().String("flag", "", "name of the flag to delete")
if err := defaultFlagsDeleteCmd.MarkFlagRequired("flag"); err != nil {
lwCliInst.Die(err)
}
}
53 changes: 53 additions & 0 deletions cmd/defaultFlagsGet.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Copyright © 2019 LiquidWeb

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
"fmt"

"github.com/spf13/cobra"

"github.com/liquidweb/liquidweb-cli/flags/defaults"
)

var defaultFlagsGetCmd = &cobra.Command{
Use: "get",
Short: "Get details on a flag",
Long: `Get details on a flag in the current context.

When a default flag is set (such as "zone") then any subcommand will use its
value in place if omitted. Default flags are auth context aware. For details
on auth contexts, see 'help auth'.`,
Run: func(cmd *cobra.Command, args []string) {
flagName, _ := cmd.Flags().GetString("flag")

value, err := defaults.Get(flagName)
if err != nil {
lwCliInst.Die(err)
}

fmt.Printf("flag: %s\n", flagName)
fmt.Printf("\tvalue: %+v\n", value)
},
}

func init() {
defaultFlagsCmd.AddCommand(defaultFlagsGetCmd)
defaultFlagsGetCmd.Flags().String("flag", "", "name of the flag")
if err := defaultFlagsGetCmd.MarkFlagRequired("flag"); err != nil {
lwCliInst.Die(err)
}
}
47 changes: 47 additions & 0 deletions cmd/defaultFlagsList.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
Copyright © 2019 LiquidWeb

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
"fmt"

"github.com/spf13/cobra"

"github.com/liquidweb/liquidweb-cli/flags/defaults"
)

var defaultFlagsListCmd = &cobra.Command{
Use: "list",
Short: "Display your set default flags",
Long: `Display your set default flags.

If you've never created any default flags, see 'help default-flags set'.

When a default flag is set (such as "zone") then any subcommand will use its
value in place if omitted. Default flags are auth context aware. For details
on auth contexts, see 'help auth'.`,
Run: func(cmd *cobra.Command, args []string) {
all, err := defaults.GetAll()
if err != nil {
lwCliInst.Die(err)
}
fmt.Print(all)
},
}

func init() {
defaultFlagsCmd.AddCommand(defaultFlagsListCmd)
}
Loading