Skip to content

Commit

Permalink
Fix field issue
Browse files Browse the repository at this point in the history
Signed-off-by: Vishal Anarse <vishal@civo.com>
  • Loading branch information
Vishal Anarse committed Nov 6, 2023
1 parent 604ebfa commit 0772189
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 15 deletions.
5 changes: 2 additions & 3 deletions cmd/database/database_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import (
"github.com/spf13/cobra"
)

var name, schedule string
var name, schedule, backupType string
var count int
var manual bool

// dbBackupCmd is the root command for the db backup subcommand
var dbBackupCmd = &cobra.Command{
Expand All @@ -34,7 +33,7 @@ func init() {
dbBackupCreateCmd.Flags().StringVarP(&name, "name", "n", "", "name of the database backup")
dbBackupCreateCmd.Flags().StringVarP(&schedule, "schedule", "s", "", "schedule of the database backup in the form of cronjob")
dbBackupCreateCmd.Flags().IntVarP(&count, "count", "c", 1, "number of backups to keep")
dbBackupCreateCmd.Flags().BoolVarP(&manual, "manual", "m", false, "set only if backup is manual/instant")
dbBackupCreateCmd.Flags().StringVarP(&backupType, "type", "t", "scheduled", "set the type of database backup manul/scheduled")

dbBackupCreateCmd.MarkFlagRequired("name")

Expand Down
12 changes: 6 additions & 6 deletions cmd/database/database_backup_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var dbBackupCreateCmd = &cobra.Command{
Use: "create",
Aliases: []string{"new", "add"},
Example: `Scheduled: civo database backup create <DATABASE-NAME/ID> --name <BACKUP_NAME> --schedule <SCHEDULE> --count <COUNT>\n
Manual: civo database backup create <DATABASE-NAME/ID> --name <BACKUP_NAME> --manual`,
Manual: civo database backup create <DATABASE-NAME/ID> --name <BACKUP_NAME> --type manual`,
Short: "Create a new database backup",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -46,7 +46,7 @@ var dbBackupCreateCmd = &cobra.Command{
}

backupCreateConfig := civogo.DatabaseBackupCreateRequest{}
if !manual {
if backupType != "manual" {
if common.RegionSet != "" {
client.Region = common.RegionSet
}
Expand All @@ -73,7 +73,7 @@ var dbBackupCreateCmd = &cobra.Command{

} else {
backupCreateConfig.Name = name
backupCreateConfig.IsManual = manual
backupCreateConfig.Type = backupType
}

backupCreateConfig.Region = client.Region
Expand All @@ -84,7 +84,7 @@ var dbBackupCreateCmd = &cobra.Command{
}

ow := &utility.OutputWriter{}
if !manual {
if backupType != "manual" {
ow = utility.NewOutputWriterWithMap(map[string]string{
"database_id": bk.DatabaseID,
"database_name": bk.DatabaseName,
Expand All @@ -98,7 +98,7 @@ var dbBackupCreateCmd = &cobra.Command{
"database_id": bk.DatabaseID,
"database_name": bk.DatabaseName,
"software": bk.Software,
"name": bk.Scheduled.Name,
"name": name,
})
}

Expand All @@ -108,7 +108,7 @@ var dbBackupCreateCmd = &cobra.Command{
case "custom":
ow.WriteCustomOutput(common.OutputFields)
default:
fmt.Printf("Database backup (%s) for database %s has been created\n", utility.Green(bk.Scheduled.Name), utility.Green(bk.DatabaseName))
fmt.Printf("Database backup (%s) for database %s has been created\n", utility.Green(name), utility.Green(bk.DatabaseName))
}
},
}
14 changes: 11 additions & 3 deletions cmd/database/database_backup_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,16 @@ var dbBackupListCmd = &cobra.Command{
osbk := utility.NewOutputWriter()
mbk := ""
sbk := ""
isConfiguredScheduled := false
isConfiguredManual := false

odb.StartLine()
odb.AppendDataWithLabel("database_id", utility.TrimID(backups.DatabaseID), "Database ID")
odb.AppendDataWithLabel("database_name", backups.DatabaseName, "Database Name")
odb.AppendDataWithLabel("software", backups.Software, "Software")

if backups.Scheduled.Schedule != "" {
if backups.Scheduled != nil {
isConfiguredScheduled = true
osbk.AppendDataWithLabel("name", backups.Scheduled.Name, "Backup Name")
osbk.AppendDataWithLabel("schedule", backups.Scheduled.Schedule, "Schedule")
osbk.AppendDataWithLabel("count", fmt.Sprintf("%d", backups.Scheduled.Count), "Count")
Expand All @@ -67,6 +70,7 @@ var dbBackupListCmd = &cobra.Command{
}

if backups.Manual != nil {
isConfiguredManual = true
for i, m := range backups.Manual {
if i < len(backups.Manual)-1 {
mbk += m.Backup + ", "
Expand Down Expand Up @@ -94,9 +98,13 @@ var dbBackupListCmd = &cobra.Command{
case "custom":
odb.WriteCustomOutput(common.OutputFields)
default:
fmt.Println("Scheduled Backups:")
if isConfiguredScheduled {
fmt.Println("Scheduled Backups:")
}
osbk.WriteTable()
fmt.Println("Manual Backups:")
if isConfiguredManual {
fmt.Println("Manual Backups:")
}
ombk.WriteTable()
}
},
Expand Down
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.52
github.com/civo/civogo v0.3.53
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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghf
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/civo/civogo v0.3.52 h1:x300yiN6N8cK3kd79RMxLCzsKCWnm4Nxv8+Nn8hjAEI=
github.com/civo/civogo v0.3.52/go.mod h1:54lv/FOf7gh6wE9ZwVdw4yBehk8V1CvU9aWa4v6dvW0=
github.com/civo/civogo v0.3.53 h1:PYqwTwt9YmeBRKMzfuTXBSPtE0WIsbLzhxD3V36bVlo=
github.com/civo/civogo v0.3.53/go.mod h1:54lv/FOf7gh6wE9ZwVdw4yBehk8V1CvU9aWa4v6dvW0=
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

0 comments on commit 0772189

Please sign in to comment.