Skip to content

Commit

Permalink
Add volumetype list cmd (#474)
Browse files Browse the repository at this point in the history
  • Loading branch information
uzaxirr authored Oct 3, 2024
1 parent d5933aa commit 6ecc10d
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 5 deletions.
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -159,5 +160,6 @@ func init() {
rootCmd.AddCommand(sshkey.SSHKeyCmd)
rootCmd.AddCommand(teams.TeamsCmd)
rootCmd.AddCommand(volume.VolumeCmd)
rootCmd.AddCommand(volumetype.VolumeTypeCmd)

}
24 changes: 24 additions & 0 deletions cmd/volumetype/volumetype.go
Original file line number Diff line number Diff line change
@@ -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)
}
47 changes: 47 additions & 0 deletions cmd/volumetype/volumetype_list.go
Original file line number Diff line number Diff line change
@@ -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()
},
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down

0 comments on commit 6ecc10d

Please sign in to comment.