Skip to content

Commit

Permalink
Add volumetype list cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
uzaxirr committed Oct 2, 2024
1 parent d5933aa commit 11751ef
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 11751ef

Please sign in to comment.