-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
77 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters