summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2022-03-03 10:43:53 +0100
committerMartin Polden <mpolden@mpolden.no>2022-03-03 10:56:39 +0100
commitff5be1c8f8bf0adfdc67ca330e61db769fd25c68 (patch)
treef4664731f05f699448bc176c6a3e6aa1daaf88d3 /client
parentd1a257211a98e1ca80ff7f929dd35262caa40bec (diff)
Use only one color package
Diffstat (limited to 'client')
-rw-r--r--client/go/cmd/api_key.go7
-rw-r--r--client/go/cmd/cert.go13
-rw-r--r--client/go/cmd/clone.go15
-rw-r--r--client/go/cmd/config.go6
-rw-r--r--client/go/cmd/deploy.go26
-rw-r--r--client/go/cmd/document.go7
-rw-r--r--client/go/cmd/helpers.go20
-rw-r--r--client/go/cmd/prod.go39
-rw-r--r--client/go/cmd/query.go3
-rw-r--r--client/go/cmd/root.go5
-rw-r--r--client/go/cmd/test.go38
-rw-r--r--client/go/cmd/version.go5
-rw-r--r--client/go/go.mod3
-rw-r--r--client/go/go.sum2
14 files changed, 99 insertions, 90 deletions
diff --git a/client/go/cmd/api_key.go b/client/go/cmd/api_key.go
index 438bf017a54..c6b6ae1d1e3 100644
--- a/client/go/cmd/api_key.go
+++ b/client/go/cmd/api_key.go
@@ -8,6 +8,7 @@ import (
"io/ioutil"
"log"
+ "github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/vespa-engine/vespa/client/go/util"
"github.com/vespa-engine/vespa/client/go/vespa"
@@ -124,10 +125,10 @@ func printPublicKey(system vespa.System, apiKeyFile, tenant string) error {
if err != nil {
return fmt.Errorf("failed to extract fingerprint: %w", err)
}
- log.Printf("\nThis is your public key:\n%s", color.Green(pemPublicKey))
- log.Printf("Its fingerprint is:\n%s\n", color.Cyan(fingerprint))
+ log.Printf("\nThis is your public key:\n%s", color.GreenString(string(pemPublicKey)))
+ log.Printf("Its fingerprint is:\n%s\n", color.CyanString(fingerprint))
log.Print("\nTo use this key in Vespa Cloud click 'Add custom key' at")
- log.Printf(color.Cyan("%s/tenant/%s/keys").String(), system.ConsoleURL, tenant)
+ log.Printf(color.CyanString("%s/tenant/%s/keys"), system.ConsoleURL, tenant)
log.Print("and paste the entire public key including the BEGIN and END lines.")
return nil
}
diff --git a/client/go/cmd/cert.go b/client/go/cmd/cert.go
index 5120459f7ac..7d6935a72ae 100644
--- a/client/go/cmd/cert.go
+++ b/client/go/cmd/cert.go
@@ -10,6 +10,7 @@ import (
"os"
"path/filepath"
+ "github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/vespa-engine/vespa/client/go/util"
"github.com/vespa-engine/vespa/client/go/vespa"
@@ -134,10 +135,10 @@ func doCert(_ *cobra.Command, args []string) error {
}
}
if util.PathExists(privateKeyFile) {
- return errHint(fmt.Errorf("private key %s already exists", color.Cyan(privateKeyFile)), hint)
+ return errHint(fmt.Errorf("private key %s already exists", color.CyanString(privateKeyFile)), hint)
}
if util.PathExists(certificateFile) {
- return errHint(fmt.Errorf("certificate %s already exists", color.Cyan(certificateFile)), hint)
+ return errHint(fmt.Errorf("certificate %s already exists", color.CyanString(certificateFile)), hint)
}
}
if !noApplicationPackage {
@@ -168,10 +169,10 @@ func doCert(_ *cobra.Command, args []string) error {
return fmt.Errorf("could not write private key: %w", err)
}
if !noApplicationPackage {
- printSuccess("Certificate written to ", color.Cyan(pkgCertificateFile))
+ printSuccess("Certificate written to ", color.CyanString(pkgCertificateFile))
}
- printSuccess("Certificate written to ", color.Cyan(certificateFile))
- printSuccess("Private key written to ", color.Cyan(privateKeyFile))
+ printSuccess("Certificate written to ", color.CyanString(certificateFile))
+ printSuccess("Private key written to ", color.CyanString(privateKeyFile))
return nil
}
@@ -225,6 +226,6 @@ func doCertAdd(_ *cobra.Command, args []string) error {
return fmt.Errorf("could not copy certificate file to application: %w", err)
}
- printSuccess("Certificate written to ", color.Cyan(pkgCertificateFile))
+ printSuccess("Certificate written to ", color.CyanString(pkgCertificateFile))
return nil
}
diff --git a/client/go/cmd/clone.go b/client/go/cmd/clone.go
index 1329e868a9c..a1add299712 100644
--- a/client/go/cmd/clone.go
+++ b/client/go/cmd/clone.go
@@ -17,6 +17,7 @@ import (
"strings"
"time"
+ "github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/vespa-engine/vespa/client/go/util"
)
@@ -77,7 +78,7 @@ func cloneApplication(applicationName string, applicationDir string) error {
r, err := zip.OpenReader(zipFile.Name())
if err != nil {
- return fmt.Errorf("could not open sample apps zip '%s': %w", color.Cyan(zipFile.Name()), err)
+ return fmt.Errorf("could not open sample apps zip '%s': %w", color.CyanString(zipFile.Name()), err)
}
defer r.Close()
@@ -88,20 +89,20 @@ func cloneApplication(applicationName string, applicationDir string) error {
if !found { // Create destination directory lazily when source is found
createErr := os.Mkdir(applicationDir, 0755)
if createErr != nil {
- return fmt.Errorf("could not create directory '%s': %w", color.Cyan(applicationDir), createErr)
+ return fmt.Errorf("could not create directory '%s': %w", color.CyanString(applicationDir), createErr)
}
}
found = true
if err := copy(f, applicationDir, dirPrefix); err != nil {
- return fmt.Errorf("could not copy zip entry '%s': %w", color.Cyan(f.Name), err)
+ return fmt.Errorf("could not copy zip entry '%s': %w", color.CyanString(f.Name), err)
}
}
}
if !found {
- return errHint(fmt.Errorf("could not find source application '%s'", color.Cyan(applicationName)), "Use -f to ignore the cache")
+ return errHint(fmt.Errorf("could not find source application '%s'", color.CyanString(applicationName)), "Use -f to ignore the cache")
} else {
- log.Print("Created ", color.Cyan(applicationDir))
+ log.Print("Created ", color.CyanString(applicationDir))
}
return nil
}
@@ -120,7 +121,7 @@ func fetchSampleAppsZip(destination string) error {
return fmt.Errorf("could not create temporary file: %w", err)
}
defer f.Close()
- return util.Spinner(stderr, color.Yellow("Downloading sample apps ...").String(), func() error {
+ return util.Spinner(stderr, color.YellowString("Downloading sample apps ..."), func() error {
request, err := http.NewRequest("GET", "https://github.com/vespa-engine/sample-apps/archive/refs/heads/master.zip", nil)
if err != nil {
return fmt.Errorf("invalid url: %w", err)
@@ -163,7 +164,7 @@ func openSampleAppsZip() (*os.File, error) {
return nil, errHint(fmt.Errorf("could not determine cache status: %w", err), "Try ignoring the cache with the -f flag")
}
if useCache {
- log.Print(color.Yellow("Using cached sample apps ..."))
+ log.Print(color.YellowString("Using cached sample apps ..."))
return os.Open(path)
}
}
diff --git a/client/go/cmd/config.go b/client/go/cmd/config.go
index 1680e1d32b5..59739d1c342 100644
--- a/client/go/cmd/config.go
+++ b/client/go/cmd/config.go
@@ -15,6 +15,7 @@ import (
"strconv"
"strings"
+ "github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/vespa-engine/vespa/client/go/auth0"
@@ -322,9 +323,10 @@ func (c *Config) Set(option, value string) error {
func printOption(cfg *Config, option string) {
value, ok := cfg.Get(option)
if !ok {
- value = color.Faint("<unset>").String()
+ faintColor := color.New(color.FgWhite, color.Faint)
+ value = faintColor.Sprint("<unset>")
} else {
- value = color.Cyan(value).String()
+ value = color.CyanString(value)
}
log.Printf("%s = %s", option, value)
}
diff --git a/client/go/cmd/deploy.go b/client/go/cmd/deploy.go
index 43b3abcbee9..396f42fae67 100644
--- a/client/go/cmd/deploy.go
+++ b/client/go/cmd/deploy.go
@@ -7,7 +7,9 @@ package cmd
import (
"fmt"
"log"
+ "strconv"
+ "github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/vespa-engine/vespa/client/go/util"
"github.com/vespa-engine/vespa/client/go/vespa"
@@ -81,14 +83,14 @@ $ vespa deploy -t cloud -z perf.aws-us-east-1c`,
log.Println()
if opts.IsCloud() {
- printSuccess("Triggered deployment of ", color.Cyan(pkg.Path), " with run ID ", color.Cyan(result.ID))
+ printSuccess("Triggered deployment of ", color.CyanString(pkg.Path), " with run ID ", color.CyanString(strconv.FormatInt(result.ID, 10)))
} else {
- printSuccess("Deployed ", color.Cyan(pkg.Path))
+ printSuccess("Deployed ", color.CyanString(pkg.Path))
printPrepareLog(result)
}
if opts.IsCloud() {
- log.Printf("\nUse %s for deployment status, or follow this deployment at", color.Cyan("vespa status"))
- log.Print(color.Cyan(fmt.Sprintf("%s/tenant/%s/application/%s/dev/instance/%s/job/%s-%s/run/%d",
+ log.Printf("\nUse %s for deployment status, or follow this deployment at", color.CyanString("vespa status"))
+ log.Print(color.CyanString(fmt.Sprintf("%s/tenant/%s/application/%s/dev/instance/%s/job/%s-%s/run/%d",
opts.Target.Deployment().System.ConsoleURL,
opts.Target.Deployment().Application.Tenant, opts.Target.Deployment().Application.Application, opts.Target.Deployment().Application.Instance,
opts.Target.Deployment().Zone.Environment, opts.Target.Deployment().Zone.Region,
@@ -131,8 +133,7 @@ var prepareCmd = &cobra.Command{
if err := cfg.WriteSessionID(vespa.DefaultApplication, result.ID); err != nil {
return fmt.Errorf("could not write session id: %w", err)
}
- printSuccess("Prepared ", color.Cyan(pkg.Path), " with session ", result.ID)
- printPrepareLog(result)
+ printSuccess("Prepared ", color.CyanString(pkg.Path), " with session ", result.ID)
return nil
},
}
@@ -167,7 +168,7 @@ var activateCmd = &cobra.Command{
if err != nil {
return err
}
- printSuccess("Activated ", color.Cyan(pkg.Path), " with session ", sessionID)
+ printSuccess("Activated ", color.CyanString(pkg.Path), " with session ", sessionID)
return waitForQueryService(sessionID)
},
}
@@ -182,14 +183,13 @@ func waitForQueryService(sessionOrRunID int64) error {
func printPrepareLog(result vespa.PrepareResult) {
for _, entry := range result.LogLines {
- switch l := entry.Level; l {
+ level := entry.Level
+ switch level {
case "ERROR":
- fmt.Fprint(stderr, color.Red(l))
+ level = color.RedString(level)
case "WARNING":
- fmt.Fprint(stderr, color.Yellow(l))
- default:
- fmt.Fprint(stderr, color.Reset(l))
+ level = color.YellowString(level)
}
- fmt.Fprintf(stderr, " %s", entry.Message)
+ fmt.Fprintf(stderr, "%s %s", level, entry.Message)
}
}
diff --git a/client/go/cmd/document.go b/client/go/cmd/document.go
index fa211aec108..5e5108d117d 100644
--- a/client/go/cmd/document.go
+++ b/client/go/cmd/document.go
@@ -11,6 +11,7 @@ import (
"strings"
"time"
+ "github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/vespa-engine/vespa/client/go/util"
"github.com/vespa-engine/vespa/client/go/vespa"
@@ -166,13 +167,13 @@ func printResult(result util.OperationResult, payloadOnlyOnSuccess bool) error {
}
if !result.Success {
- fmt.Fprintln(out, color.Red("Error:"), result.Message)
+ fmt.Fprintln(out, color.RedString("Error:"), result.Message)
} else if !(payloadOnlyOnSuccess && result.Payload != "") {
- fmt.Fprintln(out, color.Green("Success:"), result.Message)
+ fmt.Fprintln(out, color.GreenString("Success:"), result.Message)
}
if result.Detail != "" {
- fmt.Fprintln(out, color.Yellow(result.Detail))
+ fmt.Fprintln(out, color.YellowString(result.Detail))
}
if result.Payload != "" {
diff --git a/client/go/cmd/helpers.go b/client/go/cmd/helpers.go
index 0fcb0f6b113..d45fda58a2f 100644
--- a/client/go/cmd/helpers.go
+++ b/client/go/cmd/helpers.go
@@ -12,29 +12,31 @@ import (
"log"
"os"
"path/filepath"
+ "strconv"
"strings"
"time"
+ "github.com/fatih/color"
"github.com/vespa-engine/vespa/client/go/build"
"github.com/vespa-engine/vespa/client/go/version"
"github.com/vespa-engine/vespa/client/go/vespa"
)
func printErrHint(err error, hints ...string) {
- fmt.Fprintln(stderr, color.Red("Error:"), err)
+ fmt.Fprintln(stderr, color.RedString("Error:"), err)
for _, hint := range hints {
- fmt.Fprintln(stderr, color.Cyan("Hint:"), hint)
+ fmt.Fprintln(stderr, color.CyanString("Hint:"), hint)
}
}
func printSuccess(msg ...interface{}) {
- log.Print(color.Green("Success: "), fmt.Sprint(msg...))
+ log.Print(color.GreenString("Success: "), fmt.Sprint(msg...))
}
func printWarning(msg string, hints ...string) {
- fmt.Fprintln(stderr, color.Yellow("Warning:"), msg)
+ fmt.Fprintln(stderr, color.YellowString("Warning:"), msg)
for _, hint := range hints {
- fmt.Fprintln(stderr, color.Cyan("Hint:"), hint)
+ fmt.Fprintln(stderr, color.CyanString("Hint:"), hint)
}
}
@@ -160,7 +162,7 @@ func getService(service string, sessionOrRunID int64, cluster string) (*vespa.Se
}
timeout := time.Duration(waitSecsArg) * time.Second
if timeout > 0 {
- log.Printf("Waiting up to %d %s for %s service to become available ...", color.Cyan(waitSecsArg), color.Cyan("seconds"), color.Cyan(service))
+ log.Printf("Waiting up to %s %s for %s service to become available ...", color.CyanString(strconv.Itoa(waitSecsArg)), color.CyanString("seconds"), color.CyanString(service))
}
s, err := t.Service(service, timeout, sessionOrRunID, cluster)
if err != nil {
@@ -298,16 +300,16 @@ func waitForService(service string, sessionOrRunID int64) error {
}
timeout := time.Duration(waitSecsArg) * time.Second
if timeout > 0 {
- log.Printf("Waiting up to %d %s for service to become ready ...", color.Cyan(waitSecsArg), color.Cyan("seconds"))
+ log.Printf("Waiting up to %s %s for service to become ready ...", color.CyanString(strconv.Itoa(waitSecsArg)), color.CyanString("seconds"))
}
status, err := s.Wait(timeout)
if status/100 == 2 {
- log.Print(s.Description(), " at ", color.Cyan(s.BaseURL), " is ", color.Green("ready"))
+ log.Print(s.Description(), " at ", color.CyanString(s.BaseURL), " is ", color.GreenString("ready"))
} else {
if err == nil {
err = fmt.Errorf("status %d", status)
}
- return fmt.Errorf("%s at %s is %s: %w", s.Description(), color.Cyan(s.BaseURL), color.Red("not ready"), err)
+ return fmt.Errorf("%s at %s is %s: %w", s.Description(), color.CyanString(s.BaseURL), color.RedString("not ready"), err)
}
return nil
}
diff --git a/client/go/cmd/prod.go b/client/go/cmd/prod.go
index 5b30a7a9b89..4ce126bebb4 100644
--- a/client/go/cmd/prod.go
+++ b/client/go/cmd/prod.go
@@ -12,6 +12,7 @@ import (
"path/filepath"
"strings"
+ "github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/vespa-engine/vespa/client/go/util"
"github.com/vespa-engine/vespa/client/go/vespa"
@@ -78,11 +79,11 @@ https://cloud.vespa.ai/en/reference/deployment`,
return err
}
- fmt.Fprint(stdout, "This will modify any existing ", color.Yellow("deployment.xml"), " and ", color.Yellow("services.xml"),
+ fmt.Fprint(stdout, "This will modify any existing ", color.YellowString("deployment.xml"), " and ", color.YellowString("services.xml"),
"!\nBefore modification a backup of the original file will be created.\n\n")
fmt.Fprint(stdout, "A default value is suggested (shown inside brackets) based on\nthe files' existing contents. Press enter to use it.\n\n")
fmt.Fprint(stdout, "Abort the configuration at any time by pressing Ctrl-C. The\nfiles will remain untouched.\n\n")
- fmt.Fprint(stdout, "See this guide for sizing a Vespa deployment:\n", color.Green("https://docs.vespa.ai/en/performance/sizing-search.html\n\n"))
+ fmt.Fprint(stdout, "See this guide for sizing a Vespa deployment:\n", color.GreenString("https://docs.vespa.ai/en/performance/sizing-search.html\n\n"))
r := bufio.NewReader(stdin)
deploymentXML, err = updateRegions(r, deploymentXML, target.Deployment().System)
if err != nil {
@@ -165,8 +166,8 @@ $ vespa prod submit`,
if err := vespa.Submit(opts); err != nil {
return fmt.Errorf("could not submit application for deployment: %w", err)
} else {
- printSuccess("Submitted ", color.Cyan(pkg.Path), " for deployment")
- log.Printf("See %s for deployment progress\n", color.Cyan(fmt.Sprintf("%s/tenant/%s/application/%s/prod/deployment",
+ printSuccess("Submitted ", color.CyanString(pkg.Path), " for deployment")
+ log.Printf("See %s for deployment progress\n", color.CyanString(fmt.Sprintf("%s/tenant/%s/application/%s/prod/deployment",
opts.Target.Deployment().System.ConsoleURL, opts.Target.Deployment().Application.Tenant, opts.Target.Deployment().Application.Application)))
}
return nil
@@ -181,14 +182,14 @@ func writeWithBackup(pkg vespa.ApplicationPackage, filename, contents string) er
return err
}
if bytes.Equal(data, []byte(contents)) {
- fmt.Fprintf(stdout, "Not writing %s: File is unchanged\n", color.Yellow(filename))
+ fmt.Fprintf(stdout, "Not writing %s: File is unchanged\n", color.YellowString(filename))
return nil
}
renamed := false
for i := 1; i <= 1000; i++ {
bak := fmt.Sprintf("%s.%d.bak", dst, i)
if !util.PathExists(bak) {
- fmt.Fprintf(stdout, "Backing up existing %s to %s\n", color.Yellow(filename), color.Yellow(bak))
+ fmt.Fprintf(stdout, "Backing up existing %s to %s\n", color.YellowString(filename), color.YellowString(bak))
if err := os.Rename(dst, bak); err != nil {
return err
}
@@ -200,7 +201,7 @@ func writeWithBackup(pkg vespa.ApplicationPackage, filename, contents string) er
return fmt.Errorf("could not find an unused backup name for %s", dst)
}
}
- fmt.Fprintf(stdout, "Writing %s\n", color.Green(dst))
+ fmt.Fprintf(stdout, "Writing %s\n", color.GreenString(dst))
return ioutil.WriteFile(dst, []byte(contents), 0644)
}
@@ -225,9 +226,9 @@ func updateRegions(r *bufio.Reader, deploymentXML xml.Deployment, system vespa.S
}
func promptRegions(r *bufio.Reader, deploymentXML xml.Deployment, system vespa.System) (string, error) {
- fmt.Fprintln(stdout, color.Cyan("> Deployment regions"))
- fmt.Fprintf(stdout, "Documentation: %s\n", color.Green("https://cloud.vespa.ai/en/reference/zones"))
- fmt.Fprintf(stdout, "Example: %s\n\n", color.Yellow("aws-us-east-1c,aws-us-west-2a"))
+ fmt.Fprintln(stdout, color.CyanString("> Deployment regions"))
+ fmt.Fprintf(stdout, "Documentation: %s\n", color.GreenString("https://cloud.vespa.ai/en/reference/zones"))
+ fmt.Fprintf(stdout, "Example: %s\n\n", color.YellowString("aws-us-east-1c,aws-us-west-2a"))
var currentRegions []string
for _, r := range deploymentXML.Prod.Regions {
currentRegions = append(currentRegions, r.Name)
@@ -299,20 +300,20 @@ func promptNodes(r *bufio.Reader, clusterID string, defaultValue xml.Nodes) (xml
}
func promptNodeCount(r *bufio.Reader, clusterID string, nodeCount string) (string, error) {
- fmt.Fprintln(stdout, color.Cyan("\n> Node count: "+clusterID+" cluster"))
- fmt.Fprintf(stdout, "Documentation: %s\n", color.Green("https://cloud.vespa.ai/en/reference/services"))
- fmt.Fprintf(stdout, "Example: %s\nExample: %s\n\n", color.Yellow("4"), color.Yellow("[2,8]"))
+ fmt.Fprintln(stdout, color.CyanString("\n> Node count: "+clusterID+" cluster"))
+ fmt.Fprintf(stdout, "Documentation: %s\n", color.GreenString("https://cloud.vespa.ai/en/reference/services"))
+ fmt.Fprintf(stdout, "Example: %s\nExample: %s\n\n", color.YellowString("4"), color.YellowString("[2,8]"))
validator := func(input string) error {
_, _, err := xml.ParseNodeCount(input)
return err
}
- return prompt(r, fmt.Sprintf("How many nodes should the %s cluster have?", color.Cyan(clusterID)), nodeCount, validator)
+ return prompt(r, fmt.Sprintf("How many nodes should the %s cluster have?", color.CyanString(clusterID)), nodeCount, validator)
}
func promptResources(r *bufio.Reader, clusterID string, resources string) (string, error) {
- fmt.Fprintln(stdout, color.Cyan("\n> Node resources: "+clusterID+" cluster"))
- fmt.Fprintf(stdout, "Documentation: %s\n", color.Green("https://cloud.vespa.ai/en/reference/services"))
- fmt.Fprintf(stdout, "Example: %s\nExample: %s\n\n", color.Yellow("auto"), color.Yellow("vcpu=4,memory=8Gb,disk=100Gb"))
+ fmt.Fprintln(stdout, color.CyanString("\n> Node resources: "+clusterID+" cluster"))
+ fmt.Fprintf(stdout, "Documentation: %s\n", color.GreenString("https://cloud.vespa.ai/en/reference/services"))
+ fmt.Fprintf(stdout, "Example: %s\nExample: %s\n\n", color.YellowString("auto"), color.YellowString("vcpu=4,memory=8Gb,disk=100Gb"))
validator := func(input string) error {
if input == "auto" {
return nil
@@ -320,7 +321,7 @@ func promptResources(r *bufio.Reader, clusterID string, resources string) (strin
_, err := xml.ParseResources(input)
return err
}
- return prompt(r, fmt.Sprintf("Which resources should each node in the %s cluster have?", color.Cyan(clusterID)), resources, validator)
+ return prompt(r, fmt.Sprintf("Which resources should each node in the %s cluster have?", color.CyanString(clusterID)), resources, validator)
}
func readDeploymentXML(pkg vespa.ApplicationPackage) (xml.Deployment, error) {
@@ -349,7 +350,7 @@ func prompt(r *bufio.Reader, question, defaultAnswer string, validator func(inpu
for input == "" {
fmt.Fprint(stdout, question)
if defaultAnswer != "" {
- fmt.Fprint(stdout, " [", color.Yellow(defaultAnswer), "]")
+ fmt.Fprint(stdout, " [", color.YellowString(defaultAnswer), "]")
}
fmt.Fprint(stdout, " ")
diff --git a/client/go/cmd/query.go b/client/go/cmd/query.go
index 0823b4f830e..cb0fd923c4e 100644
--- a/client/go/cmd/query.go
+++ b/client/go/cmd/query.go
@@ -14,6 +14,7 @@ import (
"strings"
"time"
+ "github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/vespa-engine/vespa/client/go/curl"
"github.com/vespa-engine/vespa/client/go/util"
@@ -97,7 +98,7 @@ func query(cmd *cobra.Command, arguments []string) error {
} else if response.StatusCode/100 == 4 {
return fmt.Errorf("invalid query: %s\n%s", response.Status, util.ReaderToJSON(response.Body))
} else {
- return fmt.Errorf("%s from container at %s\n%s", response.Status, color.Cyan(url.Host), util.ReaderToJSON(response.Body))
+ return fmt.Errorf("%s from container at %s\n%s", response.Status, color.CyanString(url.Host), util.ReaderToJSON(response.Body))
}
return nil
}
diff --git a/client/go/cmd/root.go b/client/go/cmd/root.go
index 7b4a492faf4..6f29a09e177 100644
--- a/client/go/cmd/root.go
+++ b/client/go/cmd/root.go
@@ -11,7 +11,7 @@ import (
"log"
"os"
- "github.com/logrusorgru/aurora/v3"
+ "github.com/fatih/color"
"github.com/mattn/go-colorable"
"github.com/mattn/go-isatty"
"github.com/spf13/cobra"
@@ -56,7 +56,6 @@ Vespa documentation: https://docs.vespa.ai`,
apiKeyFileArg string
stdin io.ReadWriter = os.Stdin
- color = aurora.NewAurora(false)
stdout = colorable.NewColorableStdout()
stderr = colorable.NewColorableStderr()
)
@@ -103,7 +102,7 @@ func configureOutput() error {
default:
return errHint(fmt.Errorf("invalid value for %s option", colorFlag), "Must be \"auto\", \"never\" or \"always\"")
}
- color = aurora.NewAurora(colorize)
+ color.NoColor = !colorize
return nil
}
diff --git a/client/go/cmd/test.go b/client/go/cmd/test.go
index 555a689c005..56ea9277842 100644
--- a/client/go/cmd/test.go
+++ b/client/go/cmd/test.go
@@ -15,9 +15,11 @@ import (
"net/url"
"os"
"path/filepath"
+ "strconv"
"strings"
"time"
+ "github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/vespa-engine/vespa/client/go/util"
"github.com/vespa-engine/vespa/client/go/vespa"
@@ -51,7 +53,7 @@ $ vespa test src/test/application/tests/system-test/feed-and-query.json`,
if count == 1 {
plural = ""
}
- fmt.Fprintf(stdout, "\n%s %d of %d test%s failed:\n", color.Red("Failure:"), len(failed), count, plural)
+ fmt.Fprintf(stdout, "\n%s %d of %d test%s failed:\n", color.RedString("Failure:"), len(failed), count, plural)
for _, test := range failed {
fmt.Fprintln(stdout, test)
}
@@ -61,7 +63,7 @@ $ vespa test src/test/application/tests/system-test/feed-and-query.json`,
if count == 1 {
plural = ""
}
- fmt.Fprintf(stdout, "\n%s %d test%s OK\n", color.Green("Success:"), count, plural)
+ fmt.Fprintf(stdout, "\n%s %d test%s OK\n", color.GreenString("Success:"), count, plural)
return nil
}
},
@@ -154,7 +156,7 @@ func runTest(testPath string, context testContext) (string, error) {
}
if !context.dryRun {
if failure != "" {
- fmt.Fprintf(stdout, " %s\n%s:\n%s\n", color.Red("failed"), stepName, longFailure)
+ fmt.Fprintf(stdout, " %s\n%s:\n%s\n", color.RedString("failed"), stepName, longFailure)
return fmt.Sprintf("%s: %s: %s", testName, stepName, failure), nil
}
if i == 0 {
@@ -164,7 +166,7 @@ func runTest(testPath string, context testContext) (string, error) {
}
}
if !context.dryRun {
- fmt.Fprintln(stdout, color.Green(" OK"))
+ fmt.Fprintln(stdout, color.GreenString(" OK"))
}
return "", nil
}
@@ -274,12 +276,12 @@ func verify(step step, defaultCluster string, defaultParameters map[string]strin
defer response.Body.Close()
if statusCode != response.StatusCode {
- return fmt.Sprintf("Unexpected status code: %d", color.Red(response.StatusCode)),
- fmt.Sprintf("Unexpected status code\nExpected: %d\nActual: %d\nRequested: %s at %s\nResponse:\n%s",
- color.Cyan(statusCode),
- color.Red(response.StatusCode),
- color.Cyan(method),
- color.Cyan(requestUrl),
+ return fmt.Sprintf("Unexpected status code: %s", color.RedString(strconv.Itoa(response.StatusCode))),
+ fmt.Sprintf("Unexpected status code\nExpected: %s\nActual: %s\nRequested: %s at %s\nResponse:\n%s",
+ color.CyanString(strconv.Itoa(statusCode)),
+ color.RedString(strconv.Itoa(response.StatusCode)),
+ color.CyanString(method),
+ color.CyanString(requestUrl.String()),
util.ReaderToJSON(response.Body)), nil
}
@@ -308,7 +310,7 @@ func verify(step step, defaultCluster string, defaultParameters map[string]strin
failure += ": " + actual
longFailure += "\nActual: " + actual
}
- longFailure += fmt.Sprintf("\nRequested: %s at %s\nResponse:\n%s", color.Cyan(method), color.Cyan(requestUrl), string(responsePretty))
+ longFailure += fmt.Sprintf("\nRequested: %s at %s\nResponse:\n%s", color.CyanString(method), color.CyanString(requestUrl.String()), string(responsePretty))
return failure, longFailure, err
}
return "", "", err
@@ -345,9 +347,9 @@ func compare(expected interface{}, actual interface{}, path string) (string, str
}
valueMatch = true
} else {
- return fmt.Sprintf("Unexpected number of elements at %s", color.Cyan(path)),
- fmt.Sprintf("%d", color.Cyan(len(u))),
- fmt.Sprintf("%d", color.Red(len(v))),
+ return fmt.Sprintf("Unexpected number of elements at %s", color.CyanString(path)),
+ color.CyanString(strconv.Itoa(len(u))),
+ color.RedString(strconv.Itoa(len(v))),
nil
}
}
@@ -359,7 +361,7 @@ func compare(expected interface{}, actual interface{}, path string) (string, str
childPath := fmt.Sprintf("%s/%s", path, strings.ReplaceAll(strings.ReplaceAll(n, "~", "~0"), "/", "~1"))
f, ok := v[n]
if !ok {
- return fmt.Sprintf("Missing expected field at %s", color.Red(childPath)), "", "", nil
+ return fmt.Sprintf("Missing expected field at %s", color.RedString(childPath)), "", "", nil
}
if failure, expected, actual, err := compare(e, f, childPath); failure != "" || err != nil {
return failure, expected, actual, err
@@ -381,9 +383,9 @@ func compare(expected interface{}, actual interface{}, path string) (string, str
}
expectedJson, _ := json.Marshal(expected)
actualJson, _ := json.Marshal(actual)
- return fmt.Sprintf("Unexpected %s at %s", mismatched, color.Cyan(path)),
- fmt.Sprintf("%s", color.Cyan(expectedJson)),
- fmt.Sprintf("%s", color.Red(actualJson)),
+ return fmt.Sprintf("Unexpected %s at %s", mismatched, color.CyanString(path)),
+ fmt.Sprintf("%s", color.CyanString(string(expectedJson))),
+ fmt.Sprintf("%s", color.RedString(string(actualJson))),
nil
}
return "", "", "", nil
diff --git a/client/go/cmd/version.go b/client/go/cmd/version.go
index 2660dfe7d61..875fc0cc3c1 100644
--- a/client/go/cmd/version.go
+++ b/client/go/cmd/version.go
@@ -13,6 +13,7 @@ import (
"strings"
"time"
+ "github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/vespa-engine/vespa/client/go/build"
"github.com/vespa-engine/vespa/client/go/util"
@@ -73,10 +74,10 @@ func checkVersion() error {
if usingHomebrew && latest.isRecent() {
return nil // Allow some time for new release to appear in Homebrew repo
}
- log.Printf("\nNew release available: %s", color.Green(latest.Version))
+ log.Printf("\nNew release available: %s", color.GreenString(latest.Version.String()))
log.Printf("https://github.com/vespa-engine/vespa/releases/tag/v%s", latest.Version)
if usingHomebrew {
- log.Printf("\nUpgrade by running:\n%s", color.Cyan("brew update && brew upgrade vespa-cli"))
+ log.Printf("\nUpgrade by running:\n%s", color.CyanString("brew update && brew upgrade vespa-cli"))
}
return nil
}
diff --git a/client/go/go.mod b/client/go/go.mod
index 263114fd517..36060ec2014 100644
--- a/client/go/go.mod
+++ b/client/go/go.mod
@@ -4,10 +4,9 @@ go 1.15
require (
github.com/briandowns/spinner v1.16.0
- github.com/fatih/color v1.10.0 // indirect
+ github.com/fatih/color v1.10.0
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/lestrrat-go/jwx v1.2.9
- github.com/logrusorgru/aurora/v3 v3.0.0
github.com/mattn/go-colorable v0.1.8
github.com/mattn/go-isatty v0.0.13
github.com/pkg/browser v0.0.0-20210706143420-7d21f8c997e2
diff --git a/client/go/go.sum b/client/go/go.sum
index d27d422e5cc..35c8fb6bea7 100644
--- a/client/go/go.sum
+++ b/client/go/go.sum
@@ -205,8 +205,6 @@ github.com/lestrrat-go/jwx v1.2.9 h1:kS8kLI4oaBYJJ6u6rpbPI0tDYVCqo0P5u8vv1zoQ49U
github.com/lestrrat-go/jwx v1.2.9/go.mod h1:25DcLbNWArPA/Ew5CcBmewl32cJKxOk5cbepBsIJFzw=
github.com/lestrrat-go/option v1.0.0 h1:WqAWL8kh8VcSoD6xjSH34/1m8yxluXQbDeKNfvFeEO4=
github.com/lestrrat-go/option v1.0.0/go.mod h1:5ZHFbivi4xwXxhxY9XHDe2FHo6/Z7WWmtT7T5nBBp3I=
-github.com/logrusorgru/aurora/v3 v3.0.0 h1:R6zcoZZbvVcGMvDCKo45A9U/lzYyzl5NfYIvznmDfE4=
-github.com/logrusorgru/aurora/v3 v3.0.0/go.mod h1:vsR12bk5grlLvLXAYrBsb5Oc/N+LxAlxggSjiwMnCUc=
github.com/magiconair/properties v1.8.5 h1:b6kJs+EmPFMYGkow9GiUyCyOvIwYetYJ3fSaWak/Gls=
github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=