-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #366 from uzaxirr/db-versions
Add Support for DB version list
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 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,52 @@ | ||
package database | ||
|
||
import ( | ||
"github.com/civo/cli/common" | ||
"github.com/civo/cli/config" | ||
"github.com/civo/cli/utility" | ||
"github.com/spf13/cobra" | ||
"os" | ||
) | ||
|
||
var dbVersionListCmd = &cobra.Command{ | ||
Use: "versions", | ||
Aliases: []string{"version"}, | ||
Example: `civo db versions`, | ||
Short: "List all the available database versions", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
utility.EnsureCurrentRegion() | ||
|
||
client, err := config.CivoAPIClient() | ||
if err != nil { | ||
utility.Error("Creating the connection to Civo's API failed with %s", err) | ||
os.Exit(1) | ||
} | ||
|
||
if common.RegionSet != "" { | ||
client.Region = common.RegionSet | ||
} | ||
|
||
dbVersions, err := client.ListDBVersions() | ||
if err != nil { | ||
utility.Error("%s", err) | ||
os.Exit(1) | ||
} | ||
|
||
ow := utility.NewOutputWriter() | ||
|
||
for dbName, versionDetails := range dbVersions { | ||
ow.StartLine() | ||
ow.AppendDataWithLabel("name", dbName, "Name") | ||
ow.AppendDataWithLabel("version", versionDetails[0].SoftwareVersion, "version") | ||
} | ||
|
||
switch common.OutputFormat { | ||
case "json": | ||
ow.WriteMultipleObjectsJSON(common.PrettySet) | ||
case "custom": | ||
ow.WriteCustomOutput(common.OutputFields) | ||
default: | ||
ow.WriteTable() | ||
} | ||
}, | ||
} |