Skip to content

Commit

Permalink
Merge branch 'master' into db-creds
Browse files Browse the repository at this point in the history
  • Loading branch information
uzaxirr authored Feb 6, 2025
2 parents 6b68c01 + 84183e1 commit 747acdf
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func init() {
dbCreateCmd.Flags().StringVarP(&size, "size", "s", "g3.db.small", "the size of the database. You can list available DB sizes by `civo size list -s database`")
dbCreateCmd.Flags().StringVarP(&software, "software", "m", "MySQL", "the software to use for the database. One of: MySQL, PostgreSQL. Please make sure you use the correct capitalisation.")
dbCreateCmd.Flags().StringVarP(&softwareVersion, "version", "v", "", "the version of the software to use for the database.")
dbCreateCmd.Flags().BoolVarP(&waitDatabase, "wait", "w", false, "a simple flag (e.g. --wait) that will cause the CLI to spin and wait for the database to be ACTIVE")

dbUpdateCmd.Flags().IntVarP(&nodes, "nodes", "", 0, "the number of nodes for the database")
dbUpdateCmd.Flags().StringVarP(&firewallID, "firewall", "", "", "the firewall to use for the database")
Expand Down
38 changes: 37 additions & 1 deletion cmd/database/database_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"fmt"
"os"
"strings"
"time"

"github.com/briandowns/spinner"
"github.com/civo/civogo"
"github.com/civo/cli/common"
"github.com/civo/cli/config"
Expand All @@ -13,6 +15,8 @@ import (
)

var rulesFirewall string
var waitDatabase bool

var dbCreateCmd = &cobra.Command{
Use: "create",
Aliases: []string{"new", "add"},
Expand Down Expand Up @@ -168,14 +172,46 @@ var dbCreateCmd = &cobra.Command{
os.Exit(1)
}

var executionTime string

if waitDatabase {
startTime := utility.StartTime()

stillCreating := true
s := spinner.New(spinner.CharSets[9], 100*time.Millisecond)
s.Writer = os.Stderr
s.Prefix = fmt.Sprintf("Create a database called %s ", db.Name)
s.Start()

for stillCreating {
databaseCheck, err := client.FindDatabase(db.ID)
if err != nil {
utility.Error("Database %s", err)
os.Exit(1)
}
if databaseCheck.Status == "Ready" {
stillCreating = false
s.Stop()
} else {
time.Sleep(2 * time.Second)
}
}

executionTime = utility.TrackTime(startTime)
}

ow := utility.NewOutputWriterWithMap(map[string]string{"id": db.ID, "name": db.Name})
switch common.OutputFormat {
case "json":
ow.WriteSingleObjectJSON(common.PrettySet)
case "custom":
ow.WriteCustomOutput(common.OutputFields)
default:
fmt.Printf("Database (%s) with ID %s using %s with version %s has been created\n", utility.Green(db.Name), db.ID, db.Software, db.SoftwareVersion)
if executionTime != "" {
fmt.Printf("Database %s (%s) with ID %s using %s with version %s has been created in %s\n", utility.Green(db.Name), db.ID, db.Software, db.SoftwareVersion, executionTime)
} else {
fmt.Printf("Database (%s) with ID %s using %s with version %s has been created\n", utility.Green(db.Name), db.ID, db.Software, db.SoftwareVersion)
}
}
},
}

0 comments on commit 747acdf

Please sign in to comment.