diff --git a/cmd/database/database_backup.go b/cmd/database/database_backup.go index 9950393a..70bda3a9 100644 --- a/cmd/database/database_backup.go +++ b/cmd/database/database_backup.go @@ -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{ @@ -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") diff --git a/cmd/database/database_backup_create.go b/cmd/database/database_backup_create.go index a3c0f0d8..723608ba 100644 --- a/cmd/database/database_backup_create.go +++ b/cmd/database/database_backup_create.go @@ -16,7 +16,7 @@ var dbBackupCreateCmd = &cobra.Command{ Use: "create", Aliases: []string{"new", "add"}, Example: `Scheduled: civo database backup create --name --schedule --count \n - Manual: civo database backup create --name --manual`, + Manual: civo database backup create --name --type manual`, Short: "Create a new database backup", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { @@ -46,7 +46,7 @@ var dbBackupCreateCmd = &cobra.Command{ } backupCreateConfig := civogo.DatabaseBackupCreateRequest{} - if !manual { + if backupType != "manual" { if common.RegionSet != "" { client.Region = common.RegionSet } @@ -73,7 +73,7 @@ var dbBackupCreateCmd = &cobra.Command{ } else { backupCreateConfig.Name = name - backupCreateConfig.IsManual = manual + backupCreateConfig.Type = backupType } backupCreateConfig.Region = client.Region @@ -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, @@ -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, }) } @@ -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)) } }, } diff --git a/cmd/database/database_backup_list.go b/cmd/database/database_backup_list.go index c4670c3e..e4ed7202 100644 --- a/cmd/database/database_backup_list.go +++ b/cmd/database/database_backup_list.go @@ -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") @@ -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 + ", " @@ -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() } }, diff --git a/go.mod b/go.mod index 6cd59120..bc626fb7 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index d3b4b373..2431f852 100644 --- a/go.sum +++ b/go.sum @@ -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=