diff --git a/cmd/root.go b/cmd/root.go index 2599350..dabc5dc 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -22,6 +22,7 @@ import ( "github.com/civo/cli/cmd/sshkey" "github.com/civo/cli/cmd/teams" "github.com/civo/cli/cmd/volume" + "github.com/civo/cli/cmd/volumetype" "github.com/civo/cli/common" "github.com/civo/cli/config" "github.com/civo/cli/utility" @@ -159,5 +160,6 @@ func init() { rootCmd.AddCommand(sshkey.SSHKeyCmd) rootCmd.AddCommand(teams.TeamsCmd) rootCmd.AddCommand(volume.VolumeCmd) + rootCmd.AddCommand(volumetype.VolumeTypeCmd) } diff --git a/cmd/volumetype/volumetype.go b/cmd/volumetype/volumetype.go new file mode 100644 index 0000000..340f4ad --- /dev/null +++ b/cmd/volumetype/volumetype.go @@ -0,0 +1,24 @@ +package volumetype + +import ( + "errors" + "github.com/spf13/cobra" +) + +var VolumeTypeCmd = &cobra.Command{ + Use: "volumetypes", + Aliases: []string{"voltype", "volumetype"}, + Short: "Details of Civo Volume Types", + Long: `Commands to manage volume types in Civo cloud`, + RunE: func(cmd *cobra.Command, args []string) error { + err := cmd.Help() + if err != nil { + return err + } + return errors.New("a valid subcommand is required") + }, +} + +func init() { + VolumeTypeCmd.AddCommand(volumetypesListCmd) +} diff --git a/cmd/volumetype/volumetype_list.go b/cmd/volumetype/volumetype_list.go new file mode 100644 index 0000000..88a9de9 --- /dev/null +++ b/cmd/volumetype/volumetype_list.go @@ -0,0 +1,47 @@ +package volumetype + +import ( + "fmt" + "github.com/civo/cli/common" + "github.com/civo/cli/config" + "github.com/civo/cli/utility" + "github.com/spf13/cobra" + "os" + "strconv" + "strings" +) + +var volumetypesListCmd = &cobra.Command{ + Use: "ls", + Short: "List available volume types", + Long: `List the available volume types in Civo cloud`, + Run: func(cmd *cobra.Command, args []string) { + client, err := config.CivoAPIClient() + if common.RegionSet != "" { + client.Region = common.RegionSet + } + if err != nil { + utility.Error("Creating the connection to Civo's API failed with %s", err) + os.Exit(1) + } + + // Call ListVolumeTypes from SDK + volumeTypes, err := client.ListVolumeTypes() + if err != nil { + fmt.Printf("Error fetching volume types: %s\n", err) + return + } + + ow := utility.NewOutputWriter() + + // Print the volume types + for _, volumeType := range volumeTypes { + ow.StartLine() + ow.AppendDataWithLabel("name", volumeType.Name, "Name") + ow.AppendDataWithLabel("description", volumeType.Description, "Description") + ow.AppendDataWithLabel("default", strconv.FormatBool(volumeType.Enabled), "Enabled") + ow.AppendDataWithLabel("tags", strings.Join(volumeType.Labels, " "), "Labels") + } + ow.FinishAndPrintOutput() + }, +} diff --git a/go.mod b/go.mod index a8ed81b..6de310e 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/bradfitz/iter v0.0.0-20191230175014-e8f45d346db8 // indirect github.com/briandowns/spinner v1.11.1 github.com/c4milo/unpackit v0.0.0-20170704181138-4ed373e9ef1c // indirect - github.com/civo/civogo v0.3.80 + github.com/civo/civogo v0.3.82 github.com/dsnet/compress v0.0.1 // indirect github.com/fatih/color v1.13.0 // indirect github.com/google/go-github v17.0.0+incompatible // indirect diff --git a/go.sum b/go.sum index 30d6b66..b8fda7a 100644 --- a/go.sum +++ b/go.sum @@ -54,10 +54,8 @@ github.com/briandowns/spinner v1.11.1/go.mod h1:QOuQk7x+EaDASo80FEXwlwiA+j/PPIcX github.com/c4milo/unpackit v0.0.0-20170704181138-4ed373e9ef1c h1:aprLqMn7gSPT+vdDSl+/E6NLEuArwD/J7IWd8bJt5lQ= github.com/c4milo/unpackit v0.0.0-20170704181138-4ed373e9ef1c/go.mod h1:Ie6SubJv/NTO9Q0UBH0QCl3Ve50lu9hjbi5YJUw03TE= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= -github.com/civo/civogo v0.3.79 h1:Z1MbEG9CsGqSZV7UFBA0xsjk7TBGUPHjW9sM7cS5yZM= -github.com/civo/civogo v0.3.79/go.mod h1:7UCYX+qeeJbrG55E1huv+0ySxcHTqq/26FcHLVelQJM= -github.com/civo/civogo v0.3.80 h1:6ZcjiGXIabPhW+R7sdehDotjM1ofnwPMP2Cxpwns0ss= -github.com/civo/civogo v0.3.80/go.mod h1:7UCYX+qeeJbrG55E1huv+0ySxcHTqq/26FcHLVelQJM= +github.com/civo/civogo v0.3.82 h1:5UD1BrYzJ851BCnaViAW9GvrCxzU0Dgz9gFEMgI/2zY= +github.com/civo/civogo v0.3.82/go.mod h1:7UCYX+qeeJbrG55E1huv+0ySxcHTqq/26FcHLVelQJM= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= @@ -304,6 +302,7 @@ github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5q github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=