Skip to content

Implemented global --quiet (-q) flag #516

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ The civo cli have multiple global options, that you can use, like this:
--pretty Print pretty the json output
--region string Choose the region to connect to, if you use this option it will use it over the default region
-y, --yes Automatic yes to prompts; assume "yes" as answer to all prompts and run non-interactive
-q, --quiet Disables logging and run non-interactive, requires --yes flag wherever user prompts are required
```

## API Keys
Expand Down
3 changes: 1 addition & 2 deletions cmd/apikey/apikey_current.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package apikey

import (
"fmt"
"os"

"github.com/civo/cli/config"
Expand All @@ -24,7 +23,7 @@ var apikeyCurrentCmd = &cobra.Command{
if index != "" {
config.Current.Meta.CurrentAPIKey = index
config.SaveConfig()
fmt.Printf("Set the default API Key to be %s\n", utility.Green(index))
utility.Printf("Set the default API Key to be %s\n", utility.Green(index))
}

},
Expand Down
5 changes: 2 additions & 3 deletions cmd/apikey/apikey_remove.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package apikey

import (
"fmt"
"os"

"github.com/civo/cli/common"
Expand Down Expand Up @@ -41,13 +40,13 @@ var apikeyRemoveCmd = &cobra.Command{
config.SaveConfig()

if numKeys > len(config.Current.APIKeys) {
fmt.Printf("Removed the API Key %s\n", utility.Green(index))
utility.Printf("Removed the API Key %s\n", utility.Green(index))
} else {
utility.Error("The API Key %q couldn't be found", args[0])
os.Exit(1)
}
} else {
fmt.Println("Operation aborted.")
utility.Println("Operation aborted.")
}

},
Expand Down
12 changes: 8 additions & 4 deletions cmd/apikey/apikey_save.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package apikey

import (
"bufio"
"fmt"
"os"
"runtime"
"strings"
Expand Down Expand Up @@ -59,9 +58,14 @@ var apikeySaveCmd = &cobra.Command{
os.Exit(1)
}

if len(args) == 0 && common.Quiet {
utility.Info("You need to use the non-interactive way when in quiet mode")
os.Exit(1)
}

if len(args) == 0 && !loadAPIKeyFromEnv {
reader := bufio.NewReader(os.Stdin)
fmt.Printf("Enter a nice name for this account/API Key: ")
utility.Printf("Enter a nice name for this account/API Key: ")

name, err = reader.ReadString('\n')
if err != nil {
Expand All @@ -73,7 +77,7 @@ var apikeySaveCmd = &cobra.Command{
} else {
name = strings.TrimSuffix(name, "\n")
}
fmt.Printf("Enter the API key: ")
utility.Printf("Enter the API key: ")
apikeyBytes, err := term.ReadPassword(int(syscall.Stdin))
if err != nil {
utility.Error("Error reading api key %v", err)
Expand Down Expand Up @@ -140,7 +144,7 @@ var apikeySaveCmd = &cobra.Command{
case "custom":
ow.WriteCustomOutput(common.OutputFields)
default:
fmt.Printf("Saved the API Key %s\n", utility.Green(name))
utility.Printf("Saved the API Key %s\n", utility.Green(name))
}

},
Expand Down
3 changes: 1 addition & 2 deletions cmd/database/database_backup_create.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package database

import (
"fmt"
"os"

"github.com/adhocore/gronx"
Expand Down Expand Up @@ -106,7 +105,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(name), utility.Green(bk.DatabaseName))
utility.Printf("Database backup (%s) for database %s has been created\n", utility.Green(name), utility.Green(bk.DatabaseName))
}
},
}
5 changes: 2 additions & 3 deletions cmd/database/database_backup_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package database

import (
"errors"
"fmt"
"strings"

pluralize "github.com/alejandrojnm/go-pluralize"
Expand Down Expand Up @@ -99,10 +98,10 @@ var dbBackupDeleteCmd = &cobra.Command{
case "custom":
ow.WriteCustomOutput(common.OutputFields)
default:
fmt.Printf("The %s (%s) has been deleted\n", pluralize.Pluralize(len(backupList), "database backup"), utility.Green(strings.Join(dbNameList, ", ")))
utility.Printf("The %s (%s) has been deleted\n", pluralize.Pluralize(len(backupList), "database backup"), utility.Green(strings.Join(dbNameList, ", ")))
}
} else {
fmt.Println("Operation aborted")
utility.Println("Operation aborted")
}
},
}
7 changes: 3 additions & 4 deletions cmd/database/database_backup_list.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package database

import (
"fmt"
"os"

"github.com/civo/civogo"
Expand Down Expand Up @@ -82,7 +81,7 @@ func postgresScheduledBackups(backups *civogo.PaginatedDatabaseBackup) {
ow.WriteCustomOutput(common.OutputFields)
default:
if printMsg {
fmt.Println("Scheduled backup")
utility.Println("Scheduled backup")
}
ow.WriteTable()
}
Expand Down Expand Up @@ -119,7 +118,7 @@ func postgresManualBackups(backups *civogo.PaginatedDatabaseBackup) {
ow.WriteCustomOutput(common.OutputFields)
default:
if printMsg {
fmt.Println("Manual backups")
utility.Println("Manual backups")
}
ow.WriteTable()
}
Expand Down Expand Up @@ -153,7 +152,7 @@ func mysqlBackups(backups *civogo.PaginatedDatabaseBackup) {
ow.WriteCustomOutput(common.OutputFields)
default:
if printMsg {
fmt.Println("Manual backups")
utility.Println("Manual backups")
}
ow.WriteTable()
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/database/database_backup_update.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package database

import (
"fmt"
"os"

"github.com/civo/civogo"
Expand Down Expand Up @@ -75,7 +74,7 @@ var dbBackupUpdateCmd = &cobra.Command{
case "custom":
ow.WriteCustomOutput(common.OutputFields)
default:
fmt.Printf("Database backup (%s) for database %s has been update\n", utility.Green(bk.Name), utility.Green(bk.DatabaseName))
utility.Printf("Database backup (%s) for database %s has been update\n", utility.Green(bk.Name), utility.Green(bk.DatabaseName))
}
},
}
19 changes: 12 additions & 7 deletions cmd/database/database_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,13 @@ var dbCreateCmd = &cobra.Command{
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()
var s *spinner.Spinner
if !common.Quiet {
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)
Expand All @@ -191,7 +194,9 @@ var dbCreateCmd = &cobra.Command{
}
if databaseCheck.Status == "Ready" {
stillCreating = false
s.Stop()
if !common.Quiet {
s.Stop()
}
} else {
time.Sleep(2 * time.Second)
}
Expand All @@ -208,9 +213,9 @@ var dbCreateCmd = &cobra.Command{
ow.WriteCustomOutput(common.OutputFields)
default:
if executionTime != "" {
fmt.Printf("Database (%s) type %s version %s with ID %s and size %s has been created in %s\nTo get fetch the database credentials use the command:\n\ncivo database credentials %s\n", utility.Green(db.Name), strings.ToLower(db.Software), db.SoftwareVersion, db.ID, db.Size, executionTime, db.Name)
utility.Printf("Database (%s) type %s version %s with ID %s and size %s has been created in %s\nTo get fetch the database credentials use the command:\n\ncivo database credentials %s\n", utility.Green(db.Name), strings.ToLower(db.Software), db.SoftwareVersion, db.ID, db.Size, executionTime, db.Name)
} else {
fmt.Printf("Database (%s) type %s version %s with ID %s and size %s has been created\nTo get fetch the database credentials use the command:\n\ncivo database credentials %s\n", utility.Green(db.Name), strings.ToLower(db.Software), db.SoftwareVersion, db.ID, db.Size, db.Name)
utility.Printf("Database (%s) type %s version %s with ID %s and size %s has been created\nTo get fetch the database credentials use the command:\n\ncivo database credentials %s\n", utility.Green(db.Name), strings.ToLower(db.Software), db.SoftwareVersion, db.ID, db.Size, db.Name)
}
}
},
Expand Down
21 changes: 13 additions & 8 deletions cmd/database/database_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,15 @@ var dbCredentialCmd = &cobra.Command{

// Add check for database status
if db.Status == "Pending" {
fmt.Printf("The DB %s is currently being provisioned, please wait...\n", utility.Green(db.Name))

s := spinner.New(spinner.CharSets[9], 100*time.Millisecond)
s.Writer = os.Stderr
s.Prefix = fmt.Sprintf("Waiting for database (%s)... ", db.Name)
s.Start()
utility.Printf("The DB %s is currently being provisioned, please wait...\n", utility.Green(db.Name))

var s *spinner.Spinner
if !common.Quiet {
s = spinner.New(spinner.CharSets[9], 100*time.Millisecond)
s.Writer = os.Stderr
s.Prefix = fmt.Sprintf("Waiting for database (%s)... ", db.Name)
s.Start()
}

for db.Status == "Pending" {
db, err = client.FindDatabase(args[0])
Expand All @@ -61,14 +64,16 @@ var dbCredentialCmd = &cobra.Command{
}
time.Sleep(2 * time.Second)
}
s.Stop()
if !common.Quiet {
s.Stop()
}
}

connStr := strings.ToLower(db.Software) + "://" + db.DatabaseUserInfo[0].Username + ":" + db.DatabaseUserInfo[0].Password + "@" + db.PublicIPv4 + ":" + fmt.Sprintf("%d", db.DatabaseUserInfo[0].Port)

if connectionString {
for _, user := range db.DatabaseUserInfo {
fmt.Printf("%s://%s:%s@%s:%d\n", strings.ToLower(db.Software), user.Username, user.Password, db.PublicIPv4, user.Port)
utility.Printf("%s://%s:%s@%s:%d\n", strings.ToLower(db.Software), user.Username, user.Password, db.PublicIPv4, user.Port)
}
return
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/database/database_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package database

import (
"errors"
"fmt"
"strings"

pluralize "github.com/alejandrojnm/go-pluralize"
Expand Down Expand Up @@ -95,10 +94,10 @@ var dbDeleteCmd = &cobra.Command{
case "custom":
ow.WriteCustomOutput(common.OutputFields)
default:
fmt.Printf("The %s (%s) has been deleted\n", pluralize.Pluralize(len(backupList), "database"), utility.Green(strings.Join(dbNameList, ", ")))
utility.Printf("The %s (%s) has been deleted\n", pluralize.Pluralize(len(backupList), "database"), utility.Green(strings.Join(dbNameList, ", ")))
}
} else {
fmt.Println("Operation aborted")
utility.Println("Operation aborted")
}
},
}
6 changes: 2 additions & 4 deletions cmd/database/database_restore.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package database

import (
"fmt"

"github.com/civo/civogo"
"github.com/civo/cli/common"
"github.com/civo/cli/config"
Expand Down Expand Up @@ -67,10 +65,10 @@ var dbRestoreCmd = &cobra.Command{
case "custom":
ow.WriteCustomOutput(common.OutputFields)
default:
fmt.Printf("Restoring database %s from from backup %s\n", utility.Green(db.Name), utility.Green(backup))
utility.Printf("Restoring database %s from from backup %s\n", utility.Green(db.Name), utility.Green(backup))
}
} else {
fmt.Println("Aborted")
utility.Println("Aborted")
}

},
Expand Down
4 changes: 2 additions & 2 deletions cmd/database/database_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var dbShowCmd = &cobra.Command{
ow := utility.NewOutputWriter()

ow.StartLine()
fmt.Println()
utility.Println()
ow.AppendDataWithLabel("id", db.ID, "ID")
ow.AppendDataWithLabel("name", db.Name, "Name")
ow.AppendDataWithLabel("status", db.Status, "Status")
Expand All @@ -73,7 +73,7 @@ var dbShowCmd = &cobra.Command{
ow.WriteCustomOutput(common.OutputFields)
default:
ow.WriteKeyValues()
fmt.Println("To get the credentials, run : civo db credential", db.Name)
utility.Println("To get the credentials, run : civo db credential", db.Name)
}
},
}
3 changes: 1 addition & 2 deletions cmd/database/database_update.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package database

import (
"fmt"
"os"

"github.com/civo/civogo"
Expand Down Expand Up @@ -55,7 +54,7 @@ var dbUpdateCmd = &cobra.Command{
case "custom":
ow.WriteCustomOutput(common.OutputFields)
default:
fmt.Printf("The Database %s was updated\n", utility.Green(findDB.Name))
utility.Printf("The Database %s was updated\n", utility.Green(findDB.Name))
os.Exit(0)
}
},
Expand Down
3 changes: 2 additions & 1 deletion cmd/database/database_version.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package database

import (
"os"

"github.com/civo/cli/common"
"github.com/civo/cli/config"
"github.com/civo/cli/utility"
"github.com/spf13/cobra"
"os"
)

var dbVersionListCmd = &cobra.Command{
Expand Down
9 changes: 4 additions & 5 deletions cmd/domain/domain_create.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package domain

import (
"fmt"
"os"

"github.com/civo/cli/common"
Expand Down Expand Up @@ -36,10 +35,10 @@ var domainCreateCmd = &cobra.Command{
case "custom":
ow.WriteCustomOutput(common.OutputFields)
default:
fmt.Printf("Created a domain called %s with ID %s\n", utility.Green(domain.Name), utility.Green(domain.ID))
fmt.Println("Please point your domain registrar to Civo nameservers:")
fmt.Printf("%s\n", utility.Green("ns0.civo.com"))
fmt.Printf("%s\n", utility.Green("ns1.civo.com"))
utility.Printf("Created a domain called %s with ID %s\n", utility.Green(domain.Name), utility.Green(domain.ID))
utility.Println("Please point your domain registrar to Civo nameservers:")
utility.Printf("%s\n", utility.Green("ns0.civo.com"))
utility.Printf("%s\n", utility.Green("ns1.civo.com"))
}
},
}
3 changes: 1 addition & 2 deletions cmd/domain/domain_record_create.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package domain

import (
"fmt"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -83,7 +82,7 @@ var domainRecordCreateCmd = &cobra.Command{
case "custom":
ow.WriteCustomOutput(common.OutputFields)
default:
fmt.Printf("Created %s record %s for %s with a TTL of %s seconds and with a priority of %s with ID %s", utility.Green(string(record.Type)), utility.Green(record.Name), utility.Green(domain.Name), utility.Green(strconv.Itoa(record.TTL)), utility.Green(strconv.Itoa(record.Priority)), utility.Green(record.ID))
utility.Printf("Created %s record %s for %s with a TTL of %s seconds and with a priority of %s with ID %s", utility.Green(string(record.Type)), utility.Green(record.Name), utility.Green(domain.Name), utility.Green(strconv.Itoa(record.TTL)), utility.Green(strconv.Itoa(record.Priority)), utility.Green(record.ID))
}
},
}
Loading