Skip to content

Commit 6ecc10d

Browse files
authored
Add volumetype list cmd (#474)
1 parent d5933aa commit 6ecc10d

File tree

5 files changed

+77
-5
lines changed

5 files changed

+77
-5
lines changed

cmd/root.go

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/civo/cli/cmd/sshkey"
2323
"github.com/civo/cli/cmd/teams"
2424
"github.com/civo/cli/cmd/volume"
25+
"github.com/civo/cli/cmd/volumetype"
2526
"github.com/civo/cli/common"
2627
"github.com/civo/cli/config"
2728
"github.com/civo/cli/utility"
@@ -159,5 +160,6 @@ func init() {
159160
rootCmd.AddCommand(sshkey.SSHKeyCmd)
160161
rootCmd.AddCommand(teams.TeamsCmd)
161162
rootCmd.AddCommand(volume.VolumeCmd)
163+
rootCmd.AddCommand(volumetype.VolumeTypeCmd)
162164

163165
}

cmd/volumetype/volumetype.go

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package volumetype
2+
3+
import (
4+
"errors"
5+
"github.com/spf13/cobra"
6+
)
7+
8+
var VolumeTypeCmd = &cobra.Command{
9+
Use: "volumetypes",
10+
Aliases: []string{"voltype", "volumetype"},
11+
Short: "Details of Civo Volume Types",
12+
Long: `Commands to manage volume types in Civo cloud`,
13+
RunE: func(cmd *cobra.Command, args []string) error {
14+
err := cmd.Help()
15+
if err != nil {
16+
return err
17+
}
18+
return errors.New("a valid subcommand is required")
19+
},
20+
}
21+
22+
func init() {
23+
VolumeTypeCmd.AddCommand(volumetypesListCmd)
24+
}

cmd/volumetype/volumetype_list.go

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package volumetype
2+
3+
import (
4+
"fmt"
5+
"github.com/civo/cli/common"
6+
"github.com/civo/cli/config"
7+
"github.com/civo/cli/utility"
8+
"github.com/spf13/cobra"
9+
"os"
10+
"strconv"
11+
"strings"
12+
)
13+
14+
var volumetypesListCmd = &cobra.Command{
15+
Use: "ls",
16+
Short: "List available volume types",
17+
Long: `List the available volume types in Civo cloud`,
18+
Run: func(cmd *cobra.Command, args []string) {
19+
client, err := config.CivoAPIClient()
20+
if common.RegionSet != "" {
21+
client.Region = common.RegionSet
22+
}
23+
if err != nil {
24+
utility.Error("Creating the connection to Civo's API failed with %s", err)
25+
os.Exit(1)
26+
}
27+
28+
// Call ListVolumeTypes from SDK
29+
volumeTypes, err := client.ListVolumeTypes()
30+
if err != nil {
31+
fmt.Printf("Error fetching volume types: %s\n", err)
32+
return
33+
}
34+
35+
ow := utility.NewOutputWriter()
36+
37+
// Print the volume types
38+
for _, volumeType := range volumeTypes {
39+
ow.StartLine()
40+
ow.AppendDataWithLabel("name", volumeType.Name, "Name")
41+
ow.AppendDataWithLabel("description", volumeType.Description, "Description")
42+
ow.AppendDataWithLabel("default", strconv.FormatBool(volumeType.Enabled), "Enabled")
43+
ow.AppendDataWithLabel("tags", strings.Join(volumeType.Labels, " "), "Labels")
44+
}
45+
ow.FinishAndPrintOutput()
46+
},
47+
}

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/bradfitz/iter v0.0.0-20191230175014-e8f45d346db8 // indirect
1010
github.com/briandowns/spinner v1.11.1
1111
github.com/c4milo/unpackit v0.0.0-20170704181138-4ed373e9ef1c // indirect
12-
github.com/civo/civogo v0.3.80
12+
github.com/civo/civogo v0.3.82
1313
github.com/dsnet/compress v0.0.1 // indirect
1414
github.com/fatih/color v1.13.0 // indirect
1515
github.com/google/go-github v17.0.0+incompatible // indirect

go.sum

+3-4
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,8 @@ github.com/briandowns/spinner v1.11.1/go.mod h1:QOuQk7x+EaDASo80FEXwlwiA+j/PPIcX
5454
github.com/c4milo/unpackit v0.0.0-20170704181138-4ed373e9ef1c h1:aprLqMn7gSPT+vdDSl+/E6NLEuArwD/J7IWd8bJt5lQ=
5555
github.com/c4milo/unpackit v0.0.0-20170704181138-4ed373e9ef1c/go.mod h1:Ie6SubJv/NTO9Q0UBH0QCl3Ve50lu9hjbi5YJUw03TE=
5656
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
57-
github.com/civo/civogo v0.3.79 h1:Z1MbEG9CsGqSZV7UFBA0xsjk7TBGUPHjW9sM7cS5yZM=
58-
github.com/civo/civogo v0.3.79/go.mod h1:7UCYX+qeeJbrG55E1huv+0ySxcHTqq/26FcHLVelQJM=
59-
github.com/civo/civogo v0.3.80 h1:6ZcjiGXIabPhW+R7sdehDotjM1ofnwPMP2Cxpwns0ss=
60-
github.com/civo/civogo v0.3.80/go.mod h1:7UCYX+qeeJbrG55E1huv+0ySxcHTqq/26FcHLVelQJM=
57+
github.com/civo/civogo v0.3.82 h1:5UD1BrYzJ851BCnaViAW9GvrCxzU0Dgz9gFEMgI/2zY=
58+
github.com/civo/civogo v0.3.82/go.mod h1:7UCYX+qeeJbrG55E1huv+0ySxcHTqq/26FcHLVelQJM=
6159
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
6260
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
6361
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
304302
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
305303
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
306304
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
305+
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
307306
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
308307
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
309308
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=

0 commit comments

Comments
 (0)