From 3c0431a4e5acb31fe3018ab1a59dd0a0e087e36a Mon Sep 17 00:00:00 2001 From: davidvader Date: Fri, 10 May 2024 16:25:52 -0500 Subject: [PATCH 1/5] enhance: add color options --- action/build/build.go | 3 +++ action/build/cancel.go | 2 +- action/build/get.go | 2 +- action/build/restart.go | 2 +- action/build/view.go | 2 +- action/config/config.go | 3 +++ action/config/empty.go | 14 ++++++++++ action/config/file.go | 19 ++++++++------ action/config/generate.go | 11 +++++--- action/config/load.go | 45 +++++++++++++++++++++++++++++++++ action/config/remove.go | 18 +++++++++++++ action/config/update.go | 23 +++++++++++++++++ action/dashboard/dashboard.go | 3 +++ action/dashboard/view.go | 2 +- action/deployment/add.go | 2 +- action/deployment/deployment.go | 6 ++++- action/deployment/get.go | 2 +- action/deployment/view.go | 2 +- action/hook/get.go | 2 +- action/hook/hook.go | 3 +++ action/hook/view.go | 2 +- action/log/get.go | 2 +- action/log/log.go | 3 +++ action/log/view.go | 4 +-- action/pipeline/compile.go | 2 +- action/pipeline/expand.go | 2 +- action/pipeline/get.go | 2 +- action/pipeline/pipeline.go | 3 +++ action/pipeline/validate.go | 4 +-- action/pipeline/view.go | 2 +- action/repo/add.go | 2 +- action/repo/chown.go | 2 +- action/repo/get.go | 2 +- action/repo/remove.go | 2 +- action/repo/repair.go | 2 +- action/repo/repo.go | 3 +++ action/repo/update.go | 2 +- action/repo/view.go | 2 +- action/schedule/add.go | 2 +- action/schedule/get.go | 2 +- action/schedule/remove.go | 2 +- action/schedule/schedule.go | 3 +++ action/schedule/update.go | 2 +- action/schedule/view.go | 2 +- action/secret/add.go | 2 +- action/secret/get.go | 2 +- action/secret/remove.go | 2 +- action/secret/secret.go | 2 ++ action/secret/update.go | 2 +- action/secret/view.go | 2 +- action/service/get.go | 2 +- action/service/service.go | 3 +++ action/service/view.go | 2 +- action/step/get.go | 2 +- action/step/step.go | 3 +++ action/step/view.go | 2 +- action/worker/add.go | 2 +- action/worker/get.go | 2 +- action/worker/update.go | 2 +- action/worker/view.go | 2 +- action/worker/worker.go | 3 +++ command/build/cancel.go | 2 ++ command/build/get.go | 2 ++ command/build/restart.go | 2 ++ command/build/view.go | 2 ++ command/config/generate.go | 2 ++ command/config/update.go | 22 ++++++++++++++++ command/dashboard/add.go | 2 ++ command/dashboard/get.go | 2 ++ command/dashboard/update.go | 2 ++ command/dashboard/view.go | 2 ++ command/deployment/add.go | 2 ++ command/deployment/get.go | 2 ++ command/deployment/view.go | 2 ++ command/hook/get.go | 2 ++ command/hook/view.go | 2 ++ command/log/get.go | 2 ++ command/log/view.go | 2 ++ command/login/login.go | 2 ++ command/pipeline/compile.go | 2 ++ command/pipeline/expand.go | 2 ++ command/pipeline/get.go | 2 ++ command/pipeline/view.go | 2 ++ command/repo/add.go | 2 ++ command/repo/chown.go | 2 ++ command/repo/get.go | 2 ++ command/repo/remove.go | 2 ++ command/repo/repair.go | 2 ++ command/repo/update.go | 2 ++ command/repo/view.go | 2 ++ command/schedule/add.go | 2 ++ command/schedule/get.go | 2 ++ command/schedule/remove.go | 2 ++ command/schedule/update.go | 2 ++ command/schedule/view.go | 2 ++ command/secret/add.go | 2 ++ command/secret/get.go | 2 ++ command/secret/remove.go | 2 ++ command/secret/update.go | 2 ++ command/secret/view.go | 2 ++ command/service/get.go | 2 ++ command/service/view.go | 2 ++ command/step/get.go | 2 ++ command/step/view.go | 2 ++ command/version/version.go | 2 +- command/worker/add.go | 2 ++ command/worker/get.go | 2 ++ command/worker/view.go | 2 ++ go.mod | 2 ++ go.sum | 4 +++ internal/internal.go | 12 +++++++++ internal/output/color.go | 36 ++++++++++++++++++++++++++ internal/output/yaml.go | 18 +++++++++++-- internal/output/yaml_test.go | 2 +- 114 files changed, 386 insertions(+), 61 deletions(-) create mode 100644 internal/output/color.go diff --git a/action/build/build.go b/action/build/build.go index ded015ff..db2ef3aa 100644 --- a/action/build/build.go +++ b/action/build/build.go @@ -2,6 +2,8 @@ package build +import "github.com/go-vela/cli/internal/output" + // Config represents the configuration necessary // to perform build related requests with Vela. type Config struct { @@ -17,4 +19,5 @@ type Config struct { Page int PerPage int Output string + Color output.ColorOptions } diff --git a/action/build/cancel.go b/action/build/cancel.go index 36e22ce6..2d5bca9f 100644 --- a/action/build/cancel.go +++ b/action/build/cancel.go @@ -45,7 +45,7 @@ func (c *Config) Cancel(client *vela.Client) error { // output the build in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(build) + return output.YAML(build, c.Color) default: // output the build in stdout format // diff --git a/action/build/get.go b/action/build/get.go index 0f748886..9183fcda 100644 --- a/action/build/get.go +++ b/action/build/get.go @@ -62,7 +62,7 @@ func (c *Config) Get(client *vela.Client) error { // output the builds in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(builds) + return output.YAML(builds, c.Color) default: // output the builds in table format return table(builds) diff --git a/action/build/restart.go b/action/build/restart.go index 215799de..bcc241e0 100644 --- a/action/build/restart.go +++ b/action/build/restart.go @@ -45,7 +45,7 @@ func (c *Config) Restart(client *vela.Client) error { // output the build in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(build) + return output.YAML(build, c.Color) default: // output the build in stdout format // diff --git a/action/build/view.go b/action/build/view.go index de955050..0f814ed6 100644 --- a/action/build/view.go +++ b/action/build/view.go @@ -45,7 +45,7 @@ func (c *Config) View(client *vela.Client) error { // output the build in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(build) + return output.YAML(build, c.Color) default: // output the build in stdout format // diff --git a/action/config/config.go b/action/config/config.go index 30fff997..1eeaa0d7 100644 --- a/action/config/config.go +++ b/action/config/config.go @@ -2,6 +2,8 @@ package config +import "github.com/go-vela/cli/internal/output" + // Config represents the configuration necessary // to perform config related quests with Vela. type Config struct { @@ -22,4 +24,5 @@ type Config struct { UpdateFlags map[string]string RemoveFlags []string Output string + Color output.ColorOptions } diff --git a/action/config/empty.go b/action/config/empty.go index b9d2c8f8..b6e7f258 100644 --- a/action/config/empty.go +++ b/action/config/empty.go @@ -70,6 +70,20 @@ func (c *ConfigFile) Empty() bool { return false } + // check if the color is set + if c.Color != nil { + return false + } + // check if the color format is set + if len(c.ColorFormat) > 0 { + return false + } + + // check if the color theme is set + if len(c.ColorTheme) > 0 { + return false + } + // check if the org is set if len(c.Org) > 0 { return false diff --git a/action/config/file.go b/action/config/file.go index d24f3adb..6ec6e8f5 100644 --- a/action/config/file.go +++ b/action/config/file.go @@ -7,14 +7,17 @@ package config // //nolint:revive // ignore studder for package and struct name type ConfigFile struct { - API *API `yaml:"api,omitempty"` - Log *Log `yaml:"log,omitempty"` - NoGit string `yaml:"no-git,omitempty"` - Secret *Secret `yaml:"secret,omitempty"` - Compiler *Compiler `yaml:"compiler,omitempty"` - Output string `yaml:"output,omitempty"` - Org string `yaml:"org,omitempty"` - Repo string `yaml:"repo,omitempty"` + API *API `yaml:"api,omitempty"` + Log *Log `yaml:"log,omitempty"` + NoGit string `yaml:"no-git,omitempty"` + Secret *Secret `yaml:"secret,omitempty"` + Compiler *Compiler `yaml:"compiler,omitempty"` + Output string `yaml:"output,omitempty"` + Color *bool `yaml:"color,omitempty"` + ColorFormat string `yaml:"color_format,omitempty"` + ColorTheme string `yaml:"color_theme,omitempty"` + Org string `yaml:"org,omitempty"` + Repo string `yaml:"repo,omitempty"` } // API represents the API related configuration fields diff --git a/action/config/generate.go b/action/config/generate.go index fb3b3fc2..777ea80a 100644 --- a/action/config/generate.go +++ b/action/config/generate.go @@ -43,10 +43,13 @@ func (c *Config) Generate() error { URL: c.GitHub.URL, }, }, - Org: c.Org, - Repo: c.Repo, - Output: c.Output, - NoGit: c.NoGit, + Org: c.Org, + Repo: c.Repo, + Output: c.Output, + Color: &c.Color.Enabled, + ColorFormat: c.Color.Format, + ColorTheme: c.Color.Theme, + NoGit: c.NoGit, } logrus.Trace("creating file content for config file") diff --git a/action/config/load.go b/action/config/load.go index 2027e525..393daa21 100644 --- a/action/config/load.go +++ b/action/config/load.go @@ -191,6 +191,51 @@ func (c *Config) Load(ctx *cli.Context) error { continue } + // check if the color flag is available + // and if it is set in the context + if strings.Contains(f, internal.FlagColor) && + !ctx.IsSet(internal.FlagColor) { + // set the color field to value from config + c := "true" + if config.Color != nil && !*config.Color { + c = "false" + } + err = ctx.Set(internal.FlagColor, c) + if err != nil { + return err + } + + continue + } + + // check if the color format flag is available + // and if it is set in the context + if strings.Contains(f, internal.FlagColorFormat) && + !ctx.IsSet(internal.FlagColorFormat) && + len(config.ColorFormat) > 0 { + // set the color format field to value from config + err = ctx.Set(internal.FlagColorFormat, config.ColorFormat) + if err != nil { + return err + } + + continue + } + + // check if the color theme flag is available + // and if it is set in the context + if strings.Contains(f, internal.FlagColorTheme) && + !ctx.IsSet(internal.FlagColorTheme) && + len(config.ColorFormat) > 0 { + // set the color theme field to value from config + err = ctx.Set(internal.FlagColorTheme, config.ColorTheme) + if err != nil { + return err + } + + continue + } + // check if the org flag is available // and if it is set in the context if strings.Contains(f, internal.FlagOrg) && diff --git a/action/config/remove.go b/action/config/remove.go index cb9fc008..1de582e1 100644 --- a/action/config/remove.go +++ b/action/config/remove.go @@ -143,6 +143,24 @@ func (c *Config) Remove() error { // set the output field to empty in config config.Output = "" } + + // check if color flag should be removed + if strings.EqualFold(flag, internal.FlagColor) { + // set the color field to empty in config + config.Color = nil + } + + // check if color format flag should be removed + if strings.EqualFold(flag, internal.FlagColorFormat) { + // set the color format field to empty in config + config.ColorFormat = "" + } + + // check if color theme flag should be removed + if strings.EqualFold(flag, internal.FlagColorTheme) { + // set the color theme to empty in config + config.ColorTheme = "" + } } logrus.Trace("creating file content for config file") diff --git a/action/config/update.go b/action/config/update.go index 597780d3..8b02843d 100644 --- a/action/config/update.go +++ b/action/config/update.go @@ -10,6 +10,7 @@ import ( yaml "gopkg.in/yaml.v3" "github.com/go-vela/cli/internal" + "github.com/go-vela/sdk-go/vela" ) // Update modifies one or more fields from the config file based off the provided configuration. @@ -133,6 +134,28 @@ func (c *Config) Update() error { // set the output field to value provided config.Output = value } + + // check if color flag should be modified + if strings.EqualFold(key, internal.FlagColor) { + // set the color field to value provided + if value == "true" { + config.Color = vela.Bool(true) + } else { + config.Color = vela.Bool(false) + } + } + + // check if color format flag should be modified + if strings.EqualFold(key, internal.FlagColorFormat) { + // set the color format to value provided + config.ColorFormat = value + } + + // check if color theme flag should be modified + if strings.EqualFold(key, internal.FlagColorTheme) { + // set the color theme to value provided + config.ColorTheme = value + } } logrus.Trace("creating file content for config file") diff --git a/action/dashboard/dashboard.go b/action/dashboard/dashboard.go index ac35e77b..d5764e74 100644 --- a/action/dashboard/dashboard.go +++ b/action/dashboard/dashboard.go @@ -2,6 +2,8 @@ package dashboard +import "github.com/go-vela/cli/internal/output" + // Config represents the configuration necessary // to perform dashboard related requests with Vela. type Config struct { @@ -17,4 +19,5 @@ type Config struct { DropAdmins []string Full bool Output string + Color output.ColorOptions } diff --git a/action/dashboard/view.go b/action/dashboard/view.go index 925c2409..ad370518 100644 --- a/action/dashboard/view.go +++ b/action/dashboard/view.go @@ -50,7 +50,7 @@ func outputDashboard(dashboard interface{}, c *Config) error { // output the dashboard in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(dashboard) + return output.YAML(dashboard, c.Color) default: // output the dashboard in stdout format // diff --git a/action/deployment/add.go b/action/deployment/add.go index b58b05c6..77aa7ba6 100644 --- a/action/deployment/add.go +++ b/action/deployment/add.go @@ -56,7 +56,7 @@ func (c *Config) Add(client *vela.Client) error { // output the deployment in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(deployment) + return output.YAML(deployment, c.Color) default: // output the deployment in stdout format // diff --git a/action/deployment/deployment.go b/action/deployment/deployment.go index 24203a20..1a05eff2 100644 --- a/action/deployment/deployment.go +++ b/action/deployment/deployment.go @@ -2,7 +2,10 @@ package deployment -import "github.com/go-vela/types/raw" +import ( + "github.com/go-vela/cli/internal/output" + "github.com/go-vela/types/raw" +) // Config represents the configuration necessary // to perform deployment related quests with Vela. @@ -18,5 +21,6 @@ type Config struct { Page int PerPage int Output string + Color output.ColorOptions Parameters raw.StringSliceMap } diff --git a/action/deployment/get.go b/action/deployment/get.go index 23b0fd4e..c31ec2f0 100644 --- a/action/deployment/get.go +++ b/action/deployment/get.go @@ -55,7 +55,7 @@ func (c *Config) Get(client *vela.Client) error { // output the deployments in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(deployments) + return output.YAML(deployments, c.Color) default: // output the deployments in table format return table(deployments) diff --git a/action/deployment/view.go b/action/deployment/view.go index e45abc44..13ef36d2 100644 --- a/action/deployment/view.go +++ b/action/deployment/view.go @@ -44,7 +44,7 @@ func (c *Config) View(client *vela.Client) error { // output the deployment in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(deployment) + return output.YAML(deployment, c.Color) default: // output the deployment in stdout format // diff --git a/action/hook/get.go b/action/hook/get.go index c6687eae..c4549321 100644 --- a/action/hook/get.go +++ b/action/hook/get.go @@ -55,7 +55,7 @@ func (c *Config) Get(client *vela.Client) error { // output the hooks in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(hooks) + return output.YAML(hooks, c.Color) default: // output the hooks in table format return table(hooks) diff --git a/action/hook/hook.go b/action/hook/hook.go index 416873bd..e07f7554 100644 --- a/action/hook/hook.go +++ b/action/hook/hook.go @@ -2,6 +2,8 @@ package hook +import "github.com/go-vela/cli/internal/output" + // Config represents the configuration necessary // to perform hook related requests with Vela. type Config struct { @@ -12,4 +14,5 @@ type Config struct { Page int PerPage int Output string + Color output.ColorOptions } diff --git a/action/hook/view.go b/action/hook/view.go index c8fa3f65..4f8e1884 100644 --- a/action/hook/view.go +++ b/action/hook/view.go @@ -44,7 +44,7 @@ func (c *Config) View(client *vela.Client) error { // output the hook in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(hook) + return output.YAML(hook, c.Color) default: // output the hook in stdout format // diff --git a/action/log/get.go b/action/log/get.go index 7cb65626..6c7302fb 100644 --- a/action/log/get.go +++ b/action/log/get.go @@ -62,7 +62,7 @@ func (c *Config) Get(client *vela.Client) error { // output the logs in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(logs) + return output.YAML(logs, c.Color) default: // output the logs in stdout format // diff --git a/action/log/log.go b/action/log/log.go index 4c2cac87..420f7a28 100644 --- a/action/log/log.go +++ b/action/log/log.go @@ -2,6 +2,8 @@ package log +import "github.com/go-vela/cli/internal/output" + // Config represents the configuration necessary // to perform log related requests with Vela. type Config struct { @@ -14,4 +16,5 @@ type Config struct { Service int Step int Output string + Color output.ColorOptions } diff --git a/action/log/view.go b/action/log/view.go index 4db41eca..8510b097 100644 --- a/action/log/view.go +++ b/action/log/view.go @@ -46,7 +46,7 @@ func (c *Config) ViewService(client *vela.Client) error { // output the service log in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(log) + return output.YAML(log, c.Color) default: // output the service log in stdout format // @@ -92,7 +92,7 @@ func (c *Config) ViewStep(client *vela.Client) error { // output the step log in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(log) + return output.YAML(log, c.Color) default: // output the step log in stdout format // diff --git a/action/pipeline/compile.go b/action/pipeline/compile.go index 6be84004..8e03ef3e 100644 --- a/action/pipeline/compile.go +++ b/action/pipeline/compile.go @@ -52,7 +52,7 @@ func (c *Config) Compile(client *vela.Client) error { // output the pipeline in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(pipeline) + return output.YAML(pipeline, c.Color) default: // output the pipeline in stdout format // diff --git a/action/pipeline/expand.go b/action/pipeline/expand.go index 0ab4e866..89b54b72 100644 --- a/action/pipeline/expand.go +++ b/action/pipeline/expand.go @@ -52,7 +52,7 @@ func (c *Config) Expand(client *vela.Client) error { // output the pipeline in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(pipeline) + return output.YAML(pipeline, c.Color) default: // output the pipeline in stdout format // diff --git a/action/pipeline/get.go b/action/pipeline/get.go index fbf7a10b..e28fd015 100644 --- a/action/pipeline/get.go +++ b/action/pipeline/get.go @@ -55,7 +55,7 @@ func (c *Config) Get(client *vela.Client) error { // output the pipelines in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(pipelines) + return output.YAML(pipelines, c.Color) default: // output the pipelines in table format return table(pipelines) diff --git a/action/pipeline/pipeline.go b/action/pipeline/pipeline.go index 2e647f59..8eb6bad1 100644 --- a/action/pipeline/pipeline.go +++ b/action/pipeline/pipeline.go @@ -2,6 +2,8 @@ package pipeline +import "github.com/go-vela/cli/internal/output" + // Config represents the configuration necessary // to perform pipeline related requests with Vela. type Config struct { @@ -28,5 +30,6 @@ type Config struct { Page int PerPage int Output string + Color output.ColorOptions PipelineType string } diff --git a/action/pipeline/validate.go b/action/pipeline/validate.go index f2ef15ce..f460ebc9 100644 --- a/action/pipeline/validate.go +++ b/action/pipeline/validate.go @@ -171,7 +171,7 @@ func (c *Config) ValidateLocal(client compiler.Engine) error { // output the validated pipeline in stdout format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#Stdout - return output.YAML(p) + return output.YAML(p, c.Color) } // ValidateRemote validates a remote pipeline based off the provided configuration. @@ -224,7 +224,7 @@ func (c *Config) ValidateRemote(client *vela.Client) error { // output the pipeline in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(pipeline) + return output.YAML(pipeline, c.Color) default: // output the pipeline in stdout format // diff --git a/action/pipeline/view.go b/action/pipeline/view.go index 1e77fb7d..b1e9bb2c 100644 --- a/action/pipeline/view.go +++ b/action/pipeline/view.go @@ -44,7 +44,7 @@ func (c *Config) View(client *vela.Client) error { // output the pipeline in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(pipeline) + return output.YAML(pipeline, c.Color) default: // output the pipeline in stdout format // diff --git a/action/repo/add.go b/action/repo/add.go index 139a58b4..077d9e6b 100644 --- a/action/repo/add.go +++ b/action/repo/add.go @@ -78,7 +78,7 @@ func (c *Config) Add(client *vela.Client) error { // output the repository in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(repo) + return output.YAML(repo, c.Color) default: // output the repository in stdout format // diff --git a/action/repo/chown.go b/action/repo/chown.go index d996a311..bc11ee6a 100644 --- a/action/repo/chown.go +++ b/action/repo/chown.go @@ -45,7 +45,7 @@ func (c *Config) Chown(client *vela.Client) error { // output the message in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(msg) + return output.YAML(msg, c.Color) default: // output the message in stdout format // diff --git a/action/repo/get.go b/action/repo/get.go index 1af81ee7..ac97dfa4 100644 --- a/action/repo/get.go +++ b/action/repo/get.go @@ -55,7 +55,7 @@ func (c *Config) Get(client *vela.Client) error { // output the repositories in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(repos) + return output.YAML(repos, c.Color) default: // output the repositories in table format return table(repos) diff --git a/action/repo/remove.go b/action/repo/remove.go index 0e2fe608..69ea2833 100644 --- a/action/repo/remove.go +++ b/action/repo/remove.go @@ -45,7 +45,7 @@ func (c *Config) Remove(client *vela.Client) error { // output the message in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(msg) + return output.YAML(msg, c.Color) default: // output the message in stdout format // diff --git a/action/repo/repair.go b/action/repo/repair.go index 4b67fa60..a2cf3573 100644 --- a/action/repo/repair.go +++ b/action/repo/repair.go @@ -43,7 +43,7 @@ func (c *Config) Repair(client *vela.Client) error { // output the message in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(msg) + return output.YAML(msg, c.Color) default: // output the message in stdout format // diff --git a/action/repo/repo.go b/action/repo/repo.go index b0d70820..80bfbff2 100644 --- a/action/repo/repo.go +++ b/action/repo/repo.go @@ -2,6 +2,8 @@ package repo +import "github.com/go-vela/cli/internal/output" + // Config represents the configuration necessary // to perform repository related requests with Vela. type Config struct { @@ -24,4 +26,5 @@ type Config struct { Page int PerPage int Output string + Color output.ColorOptions } diff --git a/action/repo/update.go b/action/repo/update.go index 7ad9b23e..d954d354 100644 --- a/action/repo/update.go +++ b/action/repo/update.go @@ -78,7 +78,7 @@ func (c *Config) Update(client *vela.Client) error { // output the repository in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(repo) + return output.YAML(repo, c.Color) default: // output the repository in stdout format // diff --git a/action/repo/view.go b/action/repo/view.go index 005d58ca..a9fc7953 100644 --- a/action/repo/view.go +++ b/action/repo/view.go @@ -44,7 +44,7 @@ func (c *Config) View(client *vela.Client) error { // output the repository in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(repo) + return output.YAML(repo, c.Color) default: // output the repository in stdout format // diff --git a/action/schedule/add.go b/action/schedule/add.go index cfb8677a..2559f85d 100644 --- a/action/schedule/add.go +++ b/action/schedule/add.go @@ -54,7 +54,7 @@ func (c *Config) Add(client *vela.Client) error { // output the schedule in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(schedule) + return output.YAML(schedule, c.Color) default: // output the schedule in stdout format // diff --git a/action/schedule/get.go b/action/schedule/get.go index cb39bade..d87c8857 100644 --- a/action/schedule/get.go +++ b/action/schedule/get.go @@ -55,7 +55,7 @@ func (c *Config) Get(client *vela.Client) error { // output the schedules in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(schedules) + return output.YAML(schedules, c.Color) default: // output the schedules in table format return table(schedules) diff --git a/action/schedule/remove.go b/action/schedule/remove.go index 11c67750..2f96ccd1 100644 --- a/action/schedule/remove.go +++ b/action/schedule/remove.go @@ -44,7 +44,7 @@ func (c *Config) Remove(client *vela.Client) error { // output the message in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(msg) + return output.YAML(msg, c.Color) default: // output the message in stdout format // diff --git a/action/schedule/schedule.go b/action/schedule/schedule.go index 420e53e8..49c5b800 100644 --- a/action/schedule/schedule.go +++ b/action/schedule/schedule.go @@ -2,6 +2,8 @@ package schedule +import "github.com/go-vela/cli/internal/output" + // Config represents the configuration necessary // to perform schedule related requests with Vela. type Config struct { @@ -15,4 +17,5 @@ type Config struct { PerPage int Output string Branch string + Color output.ColorOptions } diff --git a/action/schedule/update.go b/action/schedule/update.go index ccd90bbc..97221023 100644 --- a/action/schedule/update.go +++ b/action/schedule/update.go @@ -54,7 +54,7 @@ func (c *Config) Update(client *vela.Client) error { // output the schedule in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(schedule) + return output.YAML(schedule, c.Color) default: // output the schedule in stdout format // diff --git a/action/schedule/view.go b/action/schedule/view.go index 8be1997e..fd31589b 100644 --- a/action/schedule/view.go +++ b/action/schedule/view.go @@ -44,7 +44,7 @@ func (c *Config) View(client *vela.Client) error { // output the schedule in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(schedule) + return output.YAML(schedule, c.Color) default: // output the schedule in stdout format // diff --git a/action/secret/add.go b/action/secret/add.go index 0b37230e..5f77f6e6 100644 --- a/action/secret/add.go +++ b/action/secret/add.go @@ -99,7 +99,7 @@ func (c *Config) Add(client *vela.Client) error { // output the secret in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(secret) + return output.YAML(secret, c.Color) default: // output the secret in stdout format // diff --git a/action/secret/get.go b/action/secret/get.go index 7eb1e3fe..accdd16a 100644 --- a/action/secret/get.go +++ b/action/secret/get.go @@ -73,7 +73,7 @@ func (c *Config) Get(client *vela.Client) error { // output the secrets in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(secrets) + return output.YAML(secrets, c.Color) default: // output the secrets in table format return table(secrets) diff --git a/action/secret/remove.go b/action/secret/remove.go index 01aa0a0d..6f615e77 100644 --- a/action/secret/remove.go +++ b/action/secret/remove.go @@ -62,7 +62,7 @@ func (c *Config) Remove(client *vela.Client) error { // output the msg in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(msg) + return output.YAML(msg, c.Color) default: // output the msg in stdout format // diff --git a/action/secret/secret.go b/action/secret/secret.go index 3733955b..f0a4709a 100644 --- a/action/secret/secret.go +++ b/action/secret/secret.go @@ -7,6 +7,7 @@ import ( "os" "strings" + "github.com/go-vela/cli/internal/output" "github.com/sirupsen/logrus" ) @@ -29,6 +30,7 @@ type Config struct { Page int PerPage int Output string + Color output.ColorOptions } // setValue is a helper function to check if the value diff --git a/action/secret/update.go b/action/secret/update.go index d03b6047..91fcc051 100644 --- a/action/secret/update.go +++ b/action/secret/update.go @@ -99,7 +99,7 @@ func (c *Config) Update(client *vela.Client) error { // output the secret in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(secret) + return output.YAML(secret, c.Color) default: // output the secret in stdout format // diff --git a/action/secret/view.go b/action/secret/view.go index a84e9392..2fac19d3 100644 --- a/action/secret/view.go +++ b/action/secret/view.go @@ -67,7 +67,7 @@ func (c *Config) View(client *vela.Client) error { // output the secret in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(secret) + return output.YAML(secret, c.Color) default: return outputDefault(c.Engine, secret) } diff --git a/action/service/get.go b/action/service/get.go index 1c73ec73..774d1059 100644 --- a/action/service/get.go +++ b/action/service/get.go @@ -55,7 +55,7 @@ func (c *Config) Get(client *vela.Client) error { // output the services in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(services) + return output.YAML(services, c.Color) default: // output the services in table format return table(services) diff --git a/action/service/service.go b/action/service/service.go index 5e335f30..c567a024 100644 --- a/action/service/service.go +++ b/action/service/service.go @@ -2,6 +2,8 @@ package service +import "github.com/go-vela/cli/internal/output" + // Config represents the configuration necessary // to perform service related requests with Vela. type Config struct { @@ -13,4 +15,5 @@ type Config struct { Page int PerPage int Output string + Color output.ColorOptions } diff --git a/action/service/view.go b/action/service/view.go index 785b4483..7a297319 100644 --- a/action/service/view.go +++ b/action/service/view.go @@ -44,7 +44,7 @@ func (c *Config) View(client *vela.Client) error { // output the service in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(service) + return output.YAML(service, c.Color) default: // output the service in stdout format // diff --git a/action/step/get.go b/action/step/get.go index 9811fcdc..989e5168 100644 --- a/action/step/get.go +++ b/action/step/get.go @@ -55,7 +55,7 @@ func (c *Config) Get(client *vela.Client) error { // output the steps in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(steps) + return output.YAML(steps, c.Color) default: // output the steps in table format return table(steps) diff --git a/action/step/step.go b/action/step/step.go index 3d8abd39..3f7dd527 100644 --- a/action/step/step.go +++ b/action/step/step.go @@ -2,6 +2,8 @@ package step +import "github.com/go-vela/cli/internal/output" + // Config represents the configuration necessary // to perform step related requests with Vela. type Config struct { @@ -13,4 +15,5 @@ type Config struct { Page int PerPage int Output string + Color output.ColorOptions } diff --git a/action/step/view.go b/action/step/view.go index 3e90cd57..e26cf640 100644 --- a/action/step/view.go +++ b/action/step/view.go @@ -44,7 +44,7 @@ func (c *Config) View(client *vela.Client) error { // output the step in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(step) + return output.YAML(step, c.Color) default: // output the step in stdout format // diff --git a/action/worker/add.go b/action/worker/add.go index d2172566..577b483c 100644 --- a/action/worker/add.go +++ b/action/worker/add.go @@ -97,7 +97,7 @@ func (c *Config) Add(client *vela.Client) error { // output the worker in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(out) + return output.YAML(out, c.Color) default: // output the worker in stdout format // diff --git a/action/worker/get.go b/action/worker/get.go index 39decb23..e273810a 100644 --- a/action/worker/get.go +++ b/action/worker/get.go @@ -61,7 +61,7 @@ func (c *Config) Get(client *vela.Client) error { // output the workers in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(workers) + return output.YAML(workers, c.Color) default: // output the workers in table format return table(workers) diff --git a/action/worker/update.go b/action/worker/update.go index e46ace98..9926532d 100644 --- a/action/worker/update.go +++ b/action/worker/update.go @@ -56,7 +56,7 @@ func (c *Config) Update(client *vela.Client) error { // output the worker in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(worker) + return output.YAML(worker, c.Color) default: // output the worker in stdout format // diff --git a/action/worker/view.go b/action/worker/view.go index d6430812..99611da6 100644 --- a/action/worker/view.go +++ b/action/worker/view.go @@ -58,7 +58,7 @@ func (c *Config) View(client *vela.Client) error { // output the worker in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(response) + return output.YAML(response, c.Color) default: // output the worker in stdout format // diff --git a/action/worker/worker.go b/action/worker/worker.go index b8a28db3..da1c009d 100644 --- a/action/worker/worker.go +++ b/action/worker/worker.go @@ -2,6 +2,8 @@ package worker +import "github.com/go-vela/cli/internal/output" + // Config represents the configuration necessary // to perform worker related requests with Vela. type Config struct { @@ -15,4 +17,5 @@ type Config struct { BuildLimit int64 RegistrationToken bool Output string + Color output.ColorOptions } diff --git a/command/build/cancel.go b/command/build/cancel.go index 819865a5..13be734c 100644 --- a/command/build/cancel.go +++ b/command/build/cancel.go @@ -12,6 +12,7 @@ import ( "github.com/go-vela/cli/action/build" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" ) // CommandCancel defines the command for canceling a build. @@ -102,6 +103,7 @@ func cancel(c *cli.Context) error { Repo: c.String(internal.FlagRepo), Number: c.Int(internal.FlagBuild), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), } // validate build configuration diff --git a/command/build/get.go b/command/build/get.go index c36af74e..96d5bcd8 100644 --- a/command/build/get.go +++ b/command/build/get.go @@ -11,6 +11,7 @@ import ( "github.com/go-vela/cli/action/build" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" ) // CommandGet defines the command for capturing a list of builds. @@ -156,6 +157,7 @@ func get(c *cli.Context) error { Page: c.Int(internal.FlagPage), PerPage: c.Int(internal.FlagPerPage), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), } // validate build configuration diff --git a/command/build/restart.go b/command/build/restart.go index 43fef6ca..b00815c2 100644 --- a/command/build/restart.go +++ b/command/build/restart.go @@ -12,6 +12,7 @@ import ( "github.com/go-vela/cli/action/build" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" ) // CommandRestart defines the command for restarting a build. @@ -101,6 +102,7 @@ func restart(c *cli.Context) error { Repo: c.String(internal.FlagRepo), Number: c.Int(internal.FlagBuild), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), } // validate build configuration diff --git a/command/build/view.go b/command/build/view.go index 332fd259..f7677cdc 100644 --- a/command/build/view.go +++ b/command/build/view.go @@ -11,6 +11,7 @@ import ( "github.com/go-vela/cli/action/build" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" ) // CommandView defines the command for inspecting a build. @@ -104,6 +105,7 @@ func view(c *cli.Context) error { Repo: c.String(internal.FlagRepo), Number: c.Int(internal.FlagBuild), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), } // validate build configuration diff --git a/command/config/generate.go b/command/config/generate.go index 2d7e2623..542e94d3 100644 --- a/command/config/generate.go +++ b/command/config/generate.go @@ -9,6 +9,7 @@ import ( "github.com/go-vela/cli/action/config" "github.com/go-vela/cli/internal" + "github.com/go-vela/cli/internal/output" ) // CommandGenerate defines the command for producing the config file. @@ -152,6 +153,7 @@ func generate(c *cli.Context) error { LogLevel: c.String(internal.FlagLogLevel), NoGit: c.String(internal.FlagNoGit), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), Org: c.String(internal.FlagOrg), Repo: c.String(internal.FlagRepo), Engine: c.String(internal.FlagSecretEngine), diff --git a/command/config/update.go b/command/config/update.go index d5a2add5..82fa76da 100644 --- a/command/config/update.go +++ b/command/config/update.go @@ -167,6 +167,8 @@ func update(c *cli.Context) error { level := c.String(internal.FlagLogLevel) noGit := c.String(internal.FlagNoGit) output := c.String(internal.FlagOutput) + colorFmt := c.String(internal.FlagColorFormat) + colorTheme := c.String(internal.FlagColorTheme) org := c.String(internal.FlagOrg) repo := c.String(internal.FlagRepo) engine := c.String(internal.FlagSecretEngine) @@ -214,6 +216,26 @@ func update(c *cli.Context) error { conf.UpdateFlags[internal.FlagOutput] = output } + // check if the color flag should be modified + if c.IsSet(internal.FlagColor) { + color := "true" + if !c.Bool(internal.FlagColor) { + color = "false" + } + + conf.UpdateFlags[internal.FlagColor] = color + } + + // check if the color format flag should be modified + if len(colorFmt) > 0 { + conf.UpdateFlags[internal.FlagColorFormat] = colorFmt + } + + // check if the color theme flag should be modified + if len(colorTheme) > 0 { + conf.UpdateFlags[internal.FlagColorTheme] = colorTheme + } + // check if the org flag should be modified if len(org) > 0 { conf.UpdateFlags[internal.FlagOrg] = org diff --git a/command/dashboard/add.go b/command/dashboard/add.go index 00be3986..2233f8cf 100644 --- a/command/dashboard/add.go +++ b/command/dashboard/add.go @@ -11,6 +11,7 @@ import ( "github.com/go-vela/cli/action/dashboard" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" ) // CommandAdd defines the command for creating a dashboard. @@ -104,6 +105,7 @@ func add(c *cli.Context) error { Events: c.StringSlice("events"), AddAdmins: c.StringSlice("admins"), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), } // validate dashboard configuration diff --git a/command/dashboard/get.go b/command/dashboard/get.go index b52d611f..f8383fb4 100644 --- a/command/dashboard/get.go +++ b/command/dashboard/get.go @@ -11,6 +11,7 @@ import ( "github.com/go-vela/cli/action/dashboard" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" ) // CommandGet defines the command for viewing all user dashboards. @@ -70,6 +71,7 @@ func get(c *cli.Context) error { Action: internal.ActionGet, Full: c.Bool("full"), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), } // validate dashboard configuration diff --git a/command/dashboard/update.go b/command/dashboard/update.go index 985a8ad1..13eeb1bb 100644 --- a/command/dashboard/update.go +++ b/command/dashboard/update.go @@ -11,6 +11,7 @@ import ( "github.com/go-vela/cli/action/dashboard" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" ) // CommandUpdate defines the command for updating a dashboard. @@ -131,6 +132,7 @@ func update(c *cli.Context) error { AddAdmins: c.StringSlice("add-admins"), DropAdmins: c.StringSlice("drop-admins"), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), } // validate dashboard configuration diff --git a/command/dashboard/view.go b/command/dashboard/view.go index 03559af1..edca07ed 100644 --- a/command/dashboard/view.go +++ b/command/dashboard/view.go @@ -11,6 +11,7 @@ import ( "github.com/go-vela/cli/action/dashboard" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" ) // CommandView defines the command for viewing a dashboard. @@ -79,6 +80,7 @@ func view(c *cli.Context) error { ID: c.String("id"), Full: c.Bool("full"), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), } // validate dashboard configuration diff --git a/command/deployment/add.go b/command/deployment/add.go index 930d0826..e6d69c7a 100644 --- a/command/deployment/add.go +++ b/command/deployment/add.go @@ -14,6 +14,7 @@ import ( "github.com/go-vela/cli/action/deployment" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" "github.com/go-vela/types/raw" ) @@ -166,6 +167,7 @@ func add(c *cli.Context) error { Target: c.String("target"), Task: c.String("task"), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), Parameters: parameters, } diff --git a/command/deployment/get.go b/command/deployment/get.go index 6dacdcdc..bf6679c1 100644 --- a/command/deployment/get.go +++ b/command/deployment/get.go @@ -11,6 +11,7 @@ import ( "github.com/go-vela/cli/action/deployment" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" ) // CommandGet defines the command for capturing a list of deployments. @@ -110,6 +111,7 @@ func get(c *cli.Context) error { Page: c.Int(internal.FlagPage), PerPage: c.Int(internal.FlagPerPage), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), } // validate deployment configuration diff --git a/command/deployment/view.go b/command/deployment/view.go index 9d14d720..0bad5766 100644 --- a/command/deployment/view.go +++ b/command/deployment/view.go @@ -11,6 +11,7 @@ import ( "github.com/go-vela/cli/action/deployment" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" ) // CommandView defines the command for inspecting a deployment. @@ -103,6 +104,7 @@ func view(c *cli.Context) error { Repo: c.String(internal.FlagRepo), Number: c.Int("deployment"), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), } // validate deployment configuration diff --git a/command/hook/get.go b/command/hook/get.go index a1b2fb84..c527d841 100644 --- a/command/hook/get.go +++ b/command/hook/get.go @@ -11,6 +11,7 @@ import ( "github.com/go-vela/cli/action/hook" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" ) // CommandGet defines the command for capturing a list of hooks. @@ -110,6 +111,7 @@ func get(c *cli.Context) error { Page: c.Int(internal.FlagPage), PerPage: c.Int(internal.FlagPerPage), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), } // validate hook configuration diff --git a/command/hook/view.go b/command/hook/view.go index 9fce8e0f..ab79bd22 100644 --- a/command/hook/view.go +++ b/command/hook/view.go @@ -11,6 +11,7 @@ import ( "github.com/go-vela/cli/action/hook" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" ) // CommandView defines the command for inspecting a hook. @@ -102,6 +103,7 @@ func view(c *cli.Context) error { Repo: c.String(internal.FlagRepo), Number: c.Int("hook"), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), } // validate hook configuration diff --git a/command/log/get.go b/command/log/get.go index a4c09ddc..1e80f1a4 100644 --- a/command/log/get.go +++ b/command/log/get.go @@ -11,6 +11,7 @@ import ( "github.com/go-vela/cli/action/log" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" ) // CommandGet defines the command for capturing a list of build logs. @@ -118,6 +119,7 @@ func get(c *cli.Context) error { Page: c.Int(internal.FlagPage), PerPage: c.Int(internal.FlagPerPage), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), } // validate log configuration diff --git a/command/log/view.go b/command/log/view.go index 226fb999..3db236f5 100644 --- a/command/log/view.go +++ b/command/log/view.go @@ -11,6 +11,7 @@ import ( "github.com/go-vela/cli/action/log" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" ) // CommandView defines the command for inspecting a log. @@ -119,6 +120,7 @@ func view(c *cli.Context) error { Service: c.Int(internal.FlagService), Step: c.Int(internal.FlagStep), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), } // validate log configuration diff --git a/command/login/login.go b/command/login/login.go index 0ffd4761..2e63ca15 100644 --- a/command/login/login.go +++ b/command/login/login.go @@ -14,6 +14,7 @@ import ( "github.com/go-vela/cli/action/login" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" ) // CommandLogin defines the command for authenticating and logging in to Vela. @@ -164,6 +165,7 @@ func runLogin(c *cli.Context) error { LogLevel: c.String(internal.FlagLogLevel), NoGit: c.String(internal.FlagNoGit), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), Org: c.String(internal.FlagOrg), Repo: c.String(internal.FlagRepo), Engine: c.String(internal.FlagSecretEngine), diff --git a/command/pipeline/compile.go b/command/pipeline/compile.go index c83ddd5c..a212aed8 100644 --- a/command/pipeline/compile.go +++ b/command/pipeline/compile.go @@ -12,6 +12,7 @@ import ( "github.com/go-vela/cli/action/pipeline" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" ) // CommandCompile defines the command for compiling a pipeline. @@ -96,6 +97,7 @@ func compile(c *cli.Context) error { Org: c.String(internal.FlagOrg), Repo: c.String(internal.FlagRepo), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), Ref: c.String("ref"), } diff --git a/command/pipeline/expand.go b/command/pipeline/expand.go index f10c7083..4e63b11e 100644 --- a/command/pipeline/expand.go +++ b/command/pipeline/expand.go @@ -12,6 +12,7 @@ import ( "github.com/go-vela/cli/action/pipeline" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" ) // CommandExpand defines the command for expanding a pipeline. @@ -96,6 +97,7 @@ func expand(c *cli.Context) error { Org: c.String(internal.FlagOrg), Repo: c.String(internal.FlagRepo), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), Ref: c.String("ref"), } diff --git a/command/pipeline/get.go b/command/pipeline/get.go index d33ed017..128553c9 100644 --- a/command/pipeline/get.go +++ b/command/pipeline/get.go @@ -11,6 +11,7 @@ import ( "github.com/go-vela/cli/action/pipeline" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" ) // CommandGet defines the command for capturing a list of pipelines. @@ -110,6 +111,7 @@ func get(c *cli.Context) error { Page: c.Int(internal.FlagPage), PerPage: c.Int(internal.FlagPerPage), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), } // validate pipeline configuration diff --git a/command/pipeline/view.go b/command/pipeline/view.go index a74fbe22..82dcea15 100644 --- a/command/pipeline/view.go +++ b/command/pipeline/view.go @@ -12,6 +12,7 @@ import ( "github.com/go-vela/cli/action/pipeline" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" ) // CommandView defines the command for inspecting a pipeline. @@ -94,6 +95,7 @@ func view(c *cli.Context) error { Org: c.String(internal.FlagOrg), Repo: c.String(internal.FlagRepo), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), Ref: c.String("ref"), } diff --git a/command/repo/add.go b/command/repo/add.go index dc101b53..99bb3b91 100644 --- a/command/repo/add.go +++ b/command/repo/add.go @@ -12,6 +12,7 @@ import ( "github.com/go-vela/cli/action/repo" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" "github.com/go-vela/types/constants" ) @@ -192,6 +193,7 @@ func add(c *cli.Context) error { PipelineType: c.String("pipeline-type"), ApproveBuild: c.String("approve-build"), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), } // validate repo configuration diff --git a/command/repo/chown.go b/command/repo/chown.go index 2d833482..9cce7925 100644 --- a/command/repo/chown.go +++ b/command/repo/chown.go @@ -12,6 +12,7 @@ import ( "github.com/go-vela/cli/action/repo" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" ) // CommandChown defines the command for changing ownership of a repository. @@ -89,6 +90,7 @@ func chown(c *cli.Context) error { Org: c.String(internal.FlagOrg), Name: c.String(internal.FlagRepo), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), } // validate repo configuration diff --git a/command/repo/get.go b/command/repo/get.go index e48fe7bc..dfd25bf4 100644 --- a/command/repo/get.go +++ b/command/repo/get.go @@ -11,6 +11,7 @@ import ( "github.com/go-vela/cli/action/repo" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" ) // CommandGet defines the command for capturing a list of repositories. @@ -95,6 +96,7 @@ func get(c *cli.Context) error { Page: c.Int(internal.FlagPage), PerPage: c.Int(internal.FlagPerPage), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), } // validate repo configuration diff --git a/command/repo/remove.go b/command/repo/remove.go index 207abff6..586d3ea3 100644 --- a/command/repo/remove.go +++ b/command/repo/remove.go @@ -12,6 +12,7 @@ import ( "github.com/go-vela/cli/action/repo" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" ) // CommandRemove defines the command for removing a repository. @@ -88,6 +89,7 @@ func remove(c *cli.Context) error { Org: c.String(internal.FlagOrg), Name: c.String(internal.FlagRepo), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), } // validate repo configuration diff --git a/command/repo/repair.go b/command/repo/repair.go index 082bea20..3b11139f 100644 --- a/command/repo/repair.go +++ b/command/repo/repair.go @@ -12,6 +12,7 @@ import ( "github.com/go-vela/cli/action/repo" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" ) // CommandRepair defines the command for repairing settings of a repository. @@ -89,6 +90,7 @@ func repair(c *cli.Context) error { Org: c.String(internal.FlagOrg), Name: c.String(internal.FlagRepo), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), } // validate repo configuration diff --git a/command/repo/update.go b/command/repo/update.go index aa3ed6d4..fe56a77d 100644 --- a/command/repo/update.go +++ b/command/repo/update.go @@ -12,6 +12,7 @@ import ( "github.com/go-vela/cli/action/repo" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" "github.com/go-vela/types/constants" ) @@ -190,6 +191,7 @@ func update(c *cli.Context) error { PipelineType: c.String("pipeline-type"), ApproveBuild: c.String("approve-build"), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), } // validate repo configuration diff --git a/command/repo/view.go b/command/repo/view.go index 775a1aa8..7ce8fee6 100644 --- a/command/repo/view.go +++ b/command/repo/view.go @@ -11,6 +11,7 @@ import ( "github.com/go-vela/cli/action/repo" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" ) // CommandView defines the command for inspecting a repository. @@ -88,6 +89,7 @@ func view(c *cli.Context) error { Org: c.String(internal.FlagOrg), Name: c.String(internal.FlagRepo), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), } // validate repo configuration diff --git a/command/schedule/add.go b/command/schedule/add.go index d7c1fd09..2000adf0 100644 --- a/command/schedule/add.go +++ b/command/schedule/add.go @@ -12,6 +12,7 @@ import ( "github.com/go-vela/cli/action/schedule" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" ) // CommandAdd defines the command for creating a schedule. @@ -118,6 +119,7 @@ func add(c *cli.Context) error { Name: c.String(internal.FlagSchedule), Entry: c.String("entry"), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), Branch: c.String(internal.FlagBranch), } diff --git a/command/schedule/get.go b/command/schedule/get.go index 3fe0f11f..17fd90aa 100644 --- a/command/schedule/get.go +++ b/command/schedule/get.go @@ -11,6 +11,7 @@ import ( "github.com/go-vela/cli/action/schedule" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" ) // CommandGet defines the command for capturing a list of schedules. @@ -108,6 +109,7 @@ func get(c *cli.Context) error { Page: c.Int(internal.FlagPage), PerPage: c.Int(internal.FlagPerPage), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), } // validate schedule configuration diff --git a/command/schedule/remove.go b/command/schedule/remove.go index dc592e9f..d2a10710 100644 --- a/command/schedule/remove.go +++ b/command/schedule/remove.go @@ -12,6 +12,7 @@ import ( "github.com/go-vela/cli/action/schedule" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" ) // CommandRemove defines the command for removing a schedule. @@ -95,6 +96,7 @@ func remove(c *cli.Context) error { Repo: c.String(internal.FlagRepo), Name: c.String(internal.FlagSchedule), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), } // validate schedule configuration diff --git a/command/schedule/update.go b/command/schedule/update.go index d77c66d1..660a5c04 100644 --- a/command/schedule/update.go +++ b/command/schedule/update.go @@ -12,6 +12,7 @@ import ( "github.com/go-vela/cli/action/schedule" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" ) // CommandUpdate defines the command for modifying a schedule. @@ -116,6 +117,7 @@ func update(c *cli.Context) error { Name: c.String(internal.FlagSchedule), Entry: c.String("entry"), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), Branch: c.String(internal.FlagBranch), } diff --git a/command/schedule/view.go b/command/schedule/view.go index fb614a9f..31c7fedb 100644 --- a/command/schedule/view.go +++ b/command/schedule/view.go @@ -12,6 +12,7 @@ import ( "github.com/go-vela/cli/action/schedule" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" ) // CommandView defines the command for inspecting a schedule. @@ -95,6 +96,7 @@ func view(c *cli.Context) error { Repo: c.String(internal.FlagRepo), Name: c.String(internal.FlagSchedule), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), } // validate schedule configuration diff --git a/command/secret/add.go b/command/secret/add.go index 4329dfdc..bf0ed931 100644 --- a/command/secret/add.go +++ b/command/secret/add.go @@ -12,6 +12,7 @@ import ( "github.com/go-vela/cli/action/secret" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" "github.com/go-vela/types/constants" ) @@ -178,6 +179,7 @@ func add(c *cli.Context) error { AllowEvents: c.StringSlice("event"), File: c.String("file"), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), } // check if allow_command and allow_substitution are provided diff --git a/command/secret/get.go b/command/secret/get.go index cdde0c0e..c4ec13f2 100644 --- a/command/secret/get.go +++ b/command/secret/get.go @@ -11,6 +11,7 @@ import ( "github.com/go-vela/cli/action/secret" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" "github.com/go-vela/types/constants" ) @@ -139,6 +140,7 @@ func get(c *cli.Context) error { Page: c.Int(internal.FlagPage), PerPage: c.Int(internal.FlagPerPage), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), } // validate secret configuration diff --git a/command/secret/remove.go b/command/secret/remove.go index 3b0a7155..b2ca0aef 100644 --- a/command/secret/remove.go +++ b/command/secret/remove.go @@ -12,6 +12,7 @@ import ( "github.com/go-vela/cli/action/secret" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" "github.com/go-vela/types/constants" ) @@ -124,6 +125,7 @@ func remove(c *cli.Context) error { Team: c.String("team"), Name: c.String("name"), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), } // validate secret configuration diff --git a/command/secret/update.go b/command/secret/update.go index 4e4e28ee..b3d27a0c 100644 --- a/command/secret/update.go +++ b/command/secret/update.go @@ -12,6 +12,7 @@ import ( "github.com/go-vela/cli/action/secret" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" "github.com/go-vela/types/constants" ) @@ -178,6 +179,7 @@ func update(c *cli.Context) error { AllowEvents: c.StringSlice("event"), File: c.String("file"), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), } // check if allow_command and allow_substitution are provided diff --git a/command/secret/view.go b/command/secret/view.go index 7a42c12d..d73f8b84 100644 --- a/command/secret/view.go +++ b/command/secret/view.go @@ -12,6 +12,7 @@ import ( "github.com/go-vela/cli/action/secret" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" "github.com/go-vela/types/constants" ) @@ -125,6 +126,7 @@ func view(c *cli.Context) error { Team: c.String("team"), Name: c.String("name"), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), } // validate secret configuration diff --git a/command/service/get.go b/command/service/get.go index c5c7e9cb..0e3e595d 100644 --- a/command/service/get.go +++ b/command/service/get.go @@ -11,6 +11,7 @@ import ( "github.com/go-vela/cli/action/service" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" ) // CommandGet defines the command for capturing a list of services. @@ -120,6 +121,7 @@ func get(c *cli.Context) error { Page: c.Int(internal.FlagPage), PerPage: c.Int(internal.FlagPerPage), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), } // validate service configuration diff --git a/command/service/view.go b/command/service/view.go index cf4cef0a..3109b951 100644 --- a/command/service/view.go +++ b/command/service/view.go @@ -11,6 +11,7 @@ import ( "github.com/go-vela/cli/action/service" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" ) // CommandView defines the command for inspecting a service. @@ -112,6 +113,7 @@ func view(c *cli.Context) error { Build: c.Int(internal.FlagBuild), Number: c.Int(internal.FlagService), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), } // validate service configuration diff --git a/command/step/get.go b/command/step/get.go index 9237813d..724e354a 100644 --- a/command/step/get.go +++ b/command/step/get.go @@ -11,6 +11,7 @@ import ( "github.com/go-vela/cli/action/step" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" ) // CommandGet defines the command for capturing a list of steps. @@ -120,6 +121,7 @@ func get(c *cli.Context) error { Page: c.Int(internal.FlagPage), PerPage: c.Int(internal.FlagPerPage), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), } // validate step configuration diff --git a/command/step/view.go b/command/step/view.go index 884d0415..022632b6 100644 --- a/command/step/view.go +++ b/command/step/view.go @@ -11,6 +11,7 @@ import ( "github.com/go-vela/cli/action/step" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" ) // CommandView defines the command for inspecting a step. @@ -112,6 +113,7 @@ func view(c *cli.Context) error { Build: c.Int(internal.FlagBuild), Number: c.Int(internal.FlagStep), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), } // validate step configuration diff --git a/command/version/version.go b/command/version/version.go index 9e3f7c32..1858df06 100644 --- a/command/version/version.go +++ b/command/version/version.go @@ -74,7 +74,7 @@ func runVersion(c *cli.Context) error { // output the version in YAML format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#YAML - return output.YAML(version.New()) + return output.YAML(version.New(), output.ColorOptionsFromCLIContext(c)) default: // output the version in stdout format // diff --git a/command/worker/add.go b/command/worker/add.go index 76136175..a961ae38 100644 --- a/command/worker/add.go +++ b/command/worker/add.go @@ -12,6 +12,7 @@ import ( "github.com/go-vela/cli/action/worker" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" ) // CommandAdd defines the command for adding a worker. @@ -85,6 +86,7 @@ func add(c *cli.Context) error { Address: c.String(internal.FlagWorkerAddress), Hostname: c.String(internal.FlagWorkerHostname), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), } // if no hostname was passed in, parse the hostname diff --git a/command/worker/get.go b/command/worker/get.go index 69462386..aa80ca0a 100644 --- a/command/worker/get.go +++ b/command/worker/get.go @@ -13,6 +13,7 @@ import ( "github.com/go-vela/cli/action/worker" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" ) // CommandGet defines the command for capturing a list of workers. @@ -119,6 +120,7 @@ func get(c *cli.Context) error { Action: internal.ActionGet, Active: &active, Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), CheckedInBefore: before, CheckedInAfter: after, } diff --git a/command/worker/view.go b/command/worker/view.go index c7f39efb..936bfff6 100644 --- a/command/worker/view.go +++ b/command/worker/view.go @@ -11,6 +11,7 @@ import ( "github.com/go-vela/cli/action/worker" "github.com/go-vela/cli/internal" "github.com/go-vela/cli/internal/client" + "github.com/go-vela/cli/internal/output" ) // CommandView defines the command for inspecting a worker. @@ -91,6 +92,7 @@ func view(c *cli.Context) error { Hostname: c.String(internal.FlagWorkerHostname), RegistrationToken: c.Bool(internal.FlagWorkerRegistrationToken), Output: c.String(internal.FlagOutput), + Color: output.ColorOptionsFromCLIContext(c), } // validate worker configuration diff --git a/go.mod b/go.mod index 70c752d9..c0304430 100644 --- a/go.mod +++ b/go.mod @@ -36,6 +36,7 @@ require ( github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect github.com/PuerkitoBio/purell v1.1.1 // indirect github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect + github.com/alecthomas/chroma/v2 v2.13.0 // indirect github.com/aymerick/douceur v0.2.0 // indirect github.com/bytedance/sonic v1.9.1 // indirect github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect @@ -47,6 +48,7 @@ require ( github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect github.com/cyphar/filepath-securejoin v0.2.4 // indirect github.com/distribution/reference v0.5.0 // indirect + github.com/dlclark/regexp2 v1.11.0 // indirect github.com/docker/docker v26.0.0+incompatible // indirect github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-units v0.5.0 // indirect diff --git a/go.sum b/go.sum index 5af7129f..4257ad71 100644 --- a/go.sum +++ b/go.sum @@ -18,6 +18,8 @@ github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tN github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M= github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= +github.com/alecthomas/chroma/v2 v2.13.0 h1:VP72+99Fb2zEcYM0MeaWJmV+xQvz5v5cxRHd+ooU1lI= +github.com/alecthomas/chroma/v2 v2.13.0/go.mod h1:BUGjjsD+ndS6eX37YgTchSEG+Jg9Jv1GiZs9sqPqztk= github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8= github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= @@ -62,6 +64,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0= github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= +github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI= +github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= github.com/docker/docker v26.0.0+incompatible h1:Ng2qi+gdKADUa/VM+6b6YaY2nlZhk/lVJiKR/2bMudU= github.com/docker/docker v26.0.0+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= diff --git a/internal/internal.go b/internal/internal.go index 3b58b022..90865ca4 100644 --- a/internal/internal.go +++ b/internal/internal.go @@ -60,6 +60,18 @@ const ( // FlagOutput defines the key for the // flag when setting the output. FlagOutput = "output" + + // FlagColor defines the key for the + // flag when enabling/disabling color output. + FlagColor = "color" + + // FlagColorFormat defines the key for the + // flag when setting the color format. + FlagColorFormat = "color.format" + + // FlagColorTheme defines the key for the + // flag when setting the color theme. + FlagColorTheme = "color.theme" ) // log flag keys. diff --git a/internal/output/color.go b/internal/output/color.go new file mode 100644 index 00000000..4348a9a4 --- /dev/null +++ b/internal/output/color.go @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: Apache-2.0 + +package output + +import ( + "github.com/go-vela/cli/internal" + "github.com/urfave/cli/v2" +) + +// ColorOptions defines the output color options used for syntax highlighting. +type ColorOptions struct { + Enabled bool + Theme string + Format string +} + +// ColorOptionsFromCLIContext creates a ColorOptions from a CLI context. +func ColorOptionsFromCLIContext(c *cli.Context) ColorOptions { + opts := ColorOptions{ + Enabled: true, + Format: "terminal256", + Theme: "monokai", + } + + opts.Enabled = c.Bool(internal.FlagColor) + + if c.IsSet(internal.FlagColorFormat) { + opts.Format = c.String(internal.FlagColorFormat) + } + + if c.IsSet(internal.FlagColorTheme) { + opts.Theme = c.String(internal.FlagColorTheme) + } + + return opts +} diff --git a/internal/output/yaml.go b/internal/output/yaml.go index 21c2a642..58e5eed5 100644 --- a/internal/output/yaml.go +++ b/internal/output/yaml.go @@ -3,9 +3,11 @@ package output import ( + "bytes" "fmt" "os" + "github.com/alecthomas/chroma/v2/quick" "github.com/sirupsen/logrus" "gopkg.in/yaml.v3" ) @@ -13,7 +15,7 @@ import ( // YAML parses the provided input and // renders the parsed input in YAML // before outputting it to stdout. -func YAML(_input interface{}) error { +func YAML(_input interface{}, colorOpts ColorOptions) error { logrus.Debugf("creating output with %s driver", DriverYAML) // validate the input provided @@ -30,8 +32,20 @@ func YAML(_input interface{}) error { logrus.Tracef("sending output to stdout with %s driver", DriverYAML) + strOutput := string(output) + + if colorOpts.Enabled { + buf := new(bytes.Buffer) + err = quick.Highlight(buf, strOutput, "yaml", colorOpts.Format, colorOpts.Theme) + if err == nil { + strOutput = buf.String() + } else { + logrus.Warnf("unable to highlight yaml output: %v", err) + } + } + // ensure we output to stdout - fmt.Fprintln(os.Stdout, string(output)) + fmt.Fprintln(os.Stdout, strOutput) return nil } diff --git a/internal/output/yaml_test.go b/internal/output/yaml_test.go index ed45d9d2..bf0dbc58 100644 --- a/internal/output/yaml_test.go +++ b/internal/output/yaml_test.go @@ -49,7 +49,7 @@ func TestOutput_YAML(t *testing.T) { // run tests for _, test := range tests { - err := YAML(test.input) + err := YAML(test.input, ColorOptions{Format: "disabled"}) if test.failure { if err == nil { From 834df671571d8ade1ef5f85888de3f376934e5d8 Mon Sep 17 00:00:00 2001 From: davidvader Date: Fri, 10 May 2024 16:31:56 -0500 Subject: [PATCH 2/5] chore: organize code --- action/config/empty.go | 1 + cmd/vela-cli/main.go | 20 ++++++++++++++++++++ internal/output/color.go | 20 ++++++++++++++++++++ internal/output/yaml.go | 16 +++------------- 4 files changed, 44 insertions(+), 13 deletions(-) diff --git a/action/config/empty.go b/action/config/empty.go index b6e7f258..a3cc8fe4 100644 --- a/action/config/empty.go +++ b/action/config/empty.go @@ -74,6 +74,7 @@ func (c *ConfigFile) Empty() bool { if c.Color != nil { return false } + // check if the color format is set if len(c.ColorFormat) > 0 { return false diff --git a/cmd/vela-cli/main.go b/cmd/vela-cli/main.go index e2028e68..7c0c5a78 100644 --- a/cmd/vela-cli/main.go +++ b/cmd/vela-cli/main.go @@ -130,6 +130,26 @@ func main() { Usage: "set the status of syncing git repo and org with .git/ directory", Value: "false", }, + + // Color Flags + + &cli.StringFlag{ + EnvVars: []string{"VELA_COLOR"}, + Name: internal.FlagColor, + Usage: "enable or disable color output", + }, + + &cli.StringFlag{ + EnvVars: []string{"VELA_COLOR_FORMAT"}, + Name: internal.FlagColorFormat, + Usage: "enable or disable color output", + }, + + &cli.StringFlag{ + EnvVars: []string{"VELA_COLOR_THEME"}, + Name: internal.FlagColorTheme, + Usage: "configures the output color theme", + }, } // CLI Start diff --git a/internal/output/color.go b/internal/output/color.go index 4348a9a4..3289fa4f 100644 --- a/internal/output/color.go +++ b/internal/output/color.go @@ -3,7 +3,11 @@ package output import ( + "bytes" + + chroma "github.com/alecthomas/chroma/v2/quick" "github.com/go-vela/cli/internal" + "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) @@ -34,3 +38,19 @@ func ColorOptionsFromCLIContext(c *cli.Context) ColorOptions { return opts } + +// HighlightYAML uses chroma to highlight the provided yaml string. +func HighlightYAML(str string, opts ColorOptions) string { + if opts.Enabled { + buf := new(bytes.Buffer) + + err := chroma.Highlight(buf, str, "yaml", opts.Format, opts.Theme) + if err == nil { + str = buf.String() + } else { + logrus.Warnf("unable to highlight yaml output: %v", err) + } + } + + return str +} diff --git a/internal/output/yaml.go b/internal/output/yaml.go index 58e5eed5..025a1e4d 100644 --- a/internal/output/yaml.go +++ b/internal/output/yaml.go @@ -3,11 +3,9 @@ package output import ( - "bytes" "fmt" "os" - "github.com/alecthomas/chroma/v2/quick" "github.com/sirupsen/logrus" "gopkg.in/yaml.v3" ) @@ -32,17 +30,9 @@ func YAML(_input interface{}, colorOpts ColorOptions) error { logrus.Tracef("sending output to stdout with %s driver", DriverYAML) - strOutput := string(output) - - if colorOpts.Enabled { - buf := new(bytes.Buffer) - err = quick.Highlight(buf, strOutput, "yaml", colorOpts.Format, colorOpts.Theme) - if err == nil { - strOutput = buf.String() - } else { - logrus.Warnf("unable to highlight yaml output: %v", err) - } - } + // attempt to highlight the output + // returns the input and logs a warning on failure + strOutput := HighlightYAML(string(output), colorOpts) // ensure we output to stdout fmt.Fprintln(os.Stdout, strOutput) From 66164221b1d733567abb837f5041f071694a5f44 Mon Sep 17 00:00:00 2001 From: davidvader Date: Fri, 10 May 2024 16:49:16 -0500 Subject: [PATCH 3/5] fix: import order --- action/build/cancel.go | 2 +- action/build/get.go | 2 +- action/build/restart.go | 2 +- action/build/view.go | 2 +- action/dashboard/view.go | 2 +- action/deployment/add.go | 2 +- action/deployment/get.go | 2 +- action/deployment/view.go | 2 +- action/hook/get.go | 2 +- action/hook/view.go | 2 +- action/log/get.go | 2 +- action/log/view.go | 4 ++-- action/pipeline/compile.go | 2 +- action/pipeline/expand.go | 2 +- action/pipeline/get.go | 2 +- action/pipeline/validate.go | 2 +- action/pipeline/view.go | 2 +- action/repo/add.go | 2 +- action/repo/chown.go | 2 +- action/repo/get.go | 2 +- action/repo/remove.go | 2 +- action/repo/repair.go | 2 +- action/repo/update.go | 2 +- action/repo/view.go | 2 +- action/schedule/add.go | 2 +- action/schedule/get.go | 2 +- action/schedule/remove.go | 2 +- action/schedule/update.go | 2 +- action/schedule/view.go | 2 +- action/secret/add.go | 2 +- action/secret/get.go | 2 +- action/secret/remove.go | 2 +- action/secret/secret.go | 3 ++- action/secret/update.go | 2 +- action/secret/view.go | 2 +- action/service/get.go | 2 +- action/service/view.go | 2 +- action/step/get.go | 2 +- action/step/view.go | 2 +- action/worker/add.go | 2 +- action/worker/get.go | 2 +- action/worker/update.go | 2 +- action/worker/view.go | 2 +- command/version/version.go | 2 +- internal/output/color.go | 11 ++++++----- internal/output/json.go | 8 ++++++-- internal/output/json_test.go | 2 +- internal/output/yaml.go | 2 +- 48 files changed, 60 insertions(+), 54 deletions(-) diff --git a/action/build/cancel.go b/action/build/cancel.go index 2d5bca9f..8b269681 100644 --- a/action/build/cancel.go +++ b/action/build/cancel.go @@ -35,7 +35,7 @@ func (c *Config) Cancel(client *vela.Client) error { // output the build in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(build) + return output.JSON(build, c.Color) case output.DriverSpew: // output the build in spew format // diff --git a/action/build/get.go b/action/build/get.go index 9183fcda..847203fb 100644 --- a/action/build/get.go +++ b/action/build/get.go @@ -49,7 +49,7 @@ func (c *Config) Get(client *vela.Client) error { // output the builds in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(builds) + return output.JSON(builds, c.Color) case output.DriverSpew: // output the builds in spew format // diff --git a/action/build/restart.go b/action/build/restart.go index bcc241e0..b58be88b 100644 --- a/action/build/restart.go +++ b/action/build/restart.go @@ -35,7 +35,7 @@ func (c *Config) Restart(client *vela.Client) error { // output the build in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(build) + return output.JSON(build, c.Color) case output.DriverSpew: // output the build in spew format // diff --git a/action/build/view.go b/action/build/view.go index 0f814ed6..233ccf52 100644 --- a/action/build/view.go +++ b/action/build/view.go @@ -35,7 +35,7 @@ func (c *Config) View(client *vela.Client) error { // output the build in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(build) + return output.JSON(build, c.Color) case output.DriverSpew: // output the build in spew format // diff --git a/action/dashboard/view.go b/action/dashboard/view.go index ad370518..fdb666c6 100644 --- a/action/dashboard/view.go +++ b/action/dashboard/view.go @@ -40,7 +40,7 @@ func outputDashboard(dashboard interface{}, c *Config) error { // output the dashboard in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(dashboard) + return output.JSON(dashboard, c.Color) case output.DriverSpew: // output the dashboard in spew format // diff --git a/action/deployment/add.go b/action/deployment/add.go index 77aa7ba6..4fb3ed64 100644 --- a/action/deployment/add.go +++ b/action/deployment/add.go @@ -46,7 +46,7 @@ func (c *Config) Add(client *vela.Client) error { // output the deployment in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(deployment) + return output.JSON(deployment, c.Color) case output.DriverSpew: // output the deployment in spew format // diff --git a/action/deployment/get.go b/action/deployment/get.go index c31ec2f0..f7e319b8 100644 --- a/action/deployment/get.go +++ b/action/deployment/get.go @@ -42,7 +42,7 @@ func (c *Config) Get(client *vela.Client) error { // output the deployments in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(deployments) + return output.JSON(deployments, c.Color) case output.DriverSpew: // output the deployments in spew format // diff --git a/action/deployment/view.go b/action/deployment/view.go index 13ef36d2..9f31b117 100644 --- a/action/deployment/view.go +++ b/action/deployment/view.go @@ -34,7 +34,7 @@ func (c *Config) View(client *vela.Client) error { // output the deployment in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(deployment) + return output.JSON(deployment, c.Color) case output.DriverSpew: // output the deployment in spew format // diff --git a/action/hook/get.go b/action/hook/get.go index c4549321..41029ab2 100644 --- a/action/hook/get.go +++ b/action/hook/get.go @@ -42,7 +42,7 @@ func (c *Config) Get(client *vela.Client) error { // output the hooks in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(hooks) + return output.JSON(hooks, c.Color) case output.DriverSpew: // output the hooks in spew format // diff --git a/action/hook/view.go b/action/hook/view.go index 4f8e1884..9d3f9f71 100644 --- a/action/hook/view.go +++ b/action/hook/view.go @@ -34,7 +34,7 @@ func (c *Config) View(client *vela.Client) error { // output the hook in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(hook) + return output.JSON(hook, c.Color) case output.DriverSpew: // output the hook in spew format // diff --git a/action/log/get.go b/action/log/get.go index 6c7302fb..9355d807 100644 --- a/action/log/get.go +++ b/action/log/get.go @@ -52,7 +52,7 @@ func (c *Config) Get(client *vela.Client) error { // output the logs in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(logs) + return output.JSON(logs, c.Color) case output.DriverSpew: // output the logs in spew format // diff --git a/action/log/view.go b/action/log/view.go index 8510b097..e0ebdb68 100644 --- a/action/log/view.go +++ b/action/log/view.go @@ -36,7 +36,7 @@ func (c *Config) ViewService(client *vela.Client) error { // output the service log in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(log) + return output.JSON(log, c.Color) case output.DriverSpew: // output the service log in spew format // @@ -82,7 +82,7 @@ func (c *Config) ViewStep(client *vela.Client) error { // output the step log in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(log) + return output.JSON(log, c.Color) case output.DriverSpew: // output the step log in spew format // diff --git a/action/pipeline/compile.go b/action/pipeline/compile.go index 8e03ef3e..8bb1307f 100644 --- a/action/pipeline/compile.go +++ b/action/pipeline/compile.go @@ -42,7 +42,7 @@ func (c *Config) Compile(client *vela.Client) error { // output the pipeline in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(pipeline) + return output.JSON(pipeline, c.Color) case output.DriverSpew: // output the pipeline in spew format // diff --git a/action/pipeline/expand.go b/action/pipeline/expand.go index 89b54b72..e2cd0acd 100644 --- a/action/pipeline/expand.go +++ b/action/pipeline/expand.go @@ -42,7 +42,7 @@ func (c *Config) Expand(client *vela.Client) error { // output the pipeline in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(pipeline) + return output.JSON(pipeline, c.Color) case output.DriverSpew: // output the pipeline in spew format // diff --git a/action/pipeline/get.go b/action/pipeline/get.go index e28fd015..cb0c5f06 100644 --- a/action/pipeline/get.go +++ b/action/pipeline/get.go @@ -42,7 +42,7 @@ func (c *Config) Get(client *vela.Client) error { // output the pipelines in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(pipelines) + return output.JSON(pipelines, c.Color) case output.DriverSpew: // output the pipelines in spew format // diff --git a/action/pipeline/validate.go b/action/pipeline/validate.go index f460ebc9..2d95bfab 100644 --- a/action/pipeline/validate.go +++ b/action/pipeline/validate.go @@ -214,7 +214,7 @@ func (c *Config) ValidateRemote(client *vela.Client) error { // output the pipeline in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(pipeline) + return output.JSON(pipeline, c.Color) case output.DriverSpew: // output the pipeline in spew format // diff --git a/action/pipeline/view.go b/action/pipeline/view.go index b1e9bb2c..dd07186d 100644 --- a/action/pipeline/view.go +++ b/action/pipeline/view.go @@ -34,7 +34,7 @@ func (c *Config) View(client *vela.Client) error { // output the pipeline in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(pipeline) + return output.JSON(pipeline, c.Color) case output.DriverSpew: // output the pipeline in spew format // diff --git a/action/repo/add.go b/action/repo/add.go index 077d9e6b..56c7f067 100644 --- a/action/repo/add.go +++ b/action/repo/add.go @@ -68,7 +68,7 @@ func (c *Config) Add(client *vela.Client) error { // output the repository in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(repo) + return output.JSON(repo, c.Color) case output.DriverSpew: // output the repository in spew format // diff --git a/action/repo/chown.go b/action/repo/chown.go index bc11ee6a..f6f8afd8 100644 --- a/action/repo/chown.go +++ b/action/repo/chown.go @@ -35,7 +35,7 @@ func (c *Config) Chown(client *vela.Client) error { // output the message in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(msg) + return output.JSON(msg, c.Color) case output.DriverSpew: // output the message in spew format // diff --git a/action/repo/get.go b/action/repo/get.go index ac97dfa4..1c10976a 100644 --- a/action/repo/get.go +++ b/action/repo/get.go @@ -42,7 +42,7 @@ func (c *Config) Get(client *vela.Client) error { // output the repositories in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(repos) + return output.JSON(repos, c.Color) case output.DriverSpew: // output the repositories in spew format // diff --git a/action/repo/remove.go b/action/repo/remove.go index 69ea2833..00086252 100644 --- a/action/repo/remove.go +++ b/action/repo/remove.go @@ -35,7 +35,7 @@ func (c *Config) Remove(client *vela.Client) error { // output the message in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(msg) + return output.JSON(msg, c.Color) case output.DriverSpew: // output the message in spew format // diff --git a/action/repo/repair.go b/action/repo/repair.go index a2cf3573..619033dc 100644 --- a/action/repo/repair.go +++ b/action/repo/repair.go @@ -33,7 +33,7 @@ func (c *Config) Repair(client *vela.Client) error { // output the message in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(msg) + return output.JSON(msg, c.Color) case output.DriverSpew: // output the message in spew format // diff --git a/action/repo/update.go b/action/repo/update.go index d954d354..410571a4 100644 --- a/action/repo/update.go +++ b/action/repo/update.go @@ -68,7 +68,7 @@ func (c *Config) Update(client *vela.Client) error { // output the repository in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(repo) + return output.JSON(repo, c.Color) case output.DriverSpew: // output the repository in spew format // diff --git a/action/repo/view.go b/action/repo/view.go index a9fc7953..e4ea3a93 100644 --- a/action/repo/view.go +++ b/action/repo/view.go @@ -34,7 +34,7 @@ func (c *Config) View(client *vela.Client) error { // output the repository in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(repo) + return output.JSON(repo, c.Color) case output.DriverSpew: // output the repository in spew format // diff --git a/action/schedule/add.go b/action/schedule/add.go index 2559f85d..dfa5689d 100644 --- a/action/schedule/add.go +++ b/action/schedule/add.go @@ -44,7 +44,7 @@ func (c *Config) Add(client *vela.Client) error { // output the schedule in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(schedule) + return output.JSON(schedule, c.Color) case output.DriverSpew: // output the schedule in spew format // diff --git a/action/schedule/get.go b/action/schedule/get.go index d87c8857..767671ee 100644 --- a/action/schedule/get.go +++ b/action/schedule/get.go @@ -42,7 +42,7 @@ func (c *Config) Get(client *vela.Client) error { // output the schedules in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(schedules) + return output.JSON(schedules, c.Color) case output.DriverSpew: // output the schedules in spew format // diff --git a/action/schedule/remove.go b/action/schedule/remove.go index 2f96ccd1..012aa2e9 100644 --- a/action/schedule/remove.go +++ b/action/schedule/remove.go @@ -34,7 +34,7 @@ func (c *Config) Remove(client *vela.Client) error { // output the message in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(msg) + return output.JSON(msg, c.Color) case output.DriverSpew: // output the message in spew format // diff --git a/action/schedule/update.go b/action/schedule/update.go index 97221023..3268865e 100644 --- a/action/schedule/update.go +++ b/action/schedule/update.go @@ -44,7 +44,7 @@ func (c *Config) Update(client *vela.Client) error { // output the schedule in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(schedule) + return output.JSON(schedule, c.Color) case output.DriverSpew: // output the schedule in spew format // diff --git a/action/schedule/view.go b/action/schedule/view.go index fd31589b..185effcd 100644 --- a/action/schedule/view.go +++ b/action/schedule/view.go @@ -34,7 +34,7 @@ func (c *Config) View(client *vela.Client) error { // output the schedule in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(schedule) + return output.JSON(schedule, c.Color) case output.DriverSpew: // output the schedule in spew format // diff --git a/action/secret/add.go b/action/secret/add.go index 5f77f6e6..f2057376 100644 --- a/action/secret/add.go +++ b/action/secret/add.go @@ -89,7 +89,7 @@ func (c *Config) Add(client *vela.Client) error { // output the secret in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(secret) + return output.JSON(secret, c.Color) case output.DriverSpew: // output the secret in spew format // diff --git a/action/secret/get.go b/action/secret/get.go index accdd16a..75b9e9c7 100644 --- a/action/secret/get.go +++ b/action/secret/get.go @@ -60,7 +60,7 @@ func (c *Config) Get(client *vela.Client) error { // output the secrets in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(secrets) + return output.JSON(secrets, c.Color) case output.DriverSpew: // output the secrets in spew format // diff --git a/action/secret/remove.go b/action/secret/remove.go index 6f615e77..9317b9c0 100644 --- a/action/secret/remove.go +++ b/action/secret/remove.go @@ -52,7 +52,7 @@ func (c *Config) Remove(client *vela.Client) error { // output the msg in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(msg) + return output.JSON(msg, c.Color) case output.DriverSpew: // output the msg in spew format // diff --git a/action/secret/secret.go b/action/secret/secret.go index f0a4709a..a1bf13ec 100644 --- a/action/secret/secret.go +++ b/action/secret/secret.go @@ -7,8 +7,9 @@ import ( "os" "strings" - "github.com/go-vela/cli/internal/output" "github.com/sirupsen/logrus" + + "github.com/go-vela/cli/internal/output" ) // Config represents the configuration necessary diff --git a/action/secret/update.go b/action/secret/update.go index 91fcc051..6cfcc8a7 100644 --- a/action/secret/update.go +++ b/action/secret/update.go @@ -89,7 +89,7 @@ func (c *Config) Update(client *vela.Client) error { // output the secret in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(secret) + return output.JSON(secret, c.Color) case output.DriverSpew: // output the secret in spew format // diff --git a/action/secret/view.go b/action/secret/view.go index 2fac19d3..24cfbece 100644 --- a/action/secret/view.go +++ b/action/secret/view.go @@ -57,7 +57,7 @@ func (c *Config) View(client *vela.Client) error { // output the secret in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(secret) + return output.JSON(secret, c.Color) case output.DriverSpew: // output the secret in spew format // diff --git a/action/service/get.go b/action/service/get.go index 774d1059..554e7866 100644 --- a/action/service/get.go +++ b/action/service/get.go @@ -42,7 +42,7 @@ func (c *Config) Get(client *vela.Client) error { // output the services in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(services) + return output.JSON(services, c.Color) case output.DriverSpew: // output the services in spew format // diff --git a/action/service/view.go b/action/service/view.go index 7a297319..bd3543a7 100644 --- a/action/service/view.go +++ b/action/service/view.go @@ -34,7 +34,7 @@ func (c *Config) View(client *vela.Client) error { // output the service in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(service) + return output.JSON(service, c.Color) case output.DriverSpew: // output the service in spew format // diff --git a/action/step/get.go b/action/step/get.go index 989e5168..5d9173f4 100644 --- a/action/step/get.go +++ b/action/step/get.go @@ -42,7 +42,7 @@ func (c *Config) Get(client *vela.Client) error { // output the steps in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(steps) + return output.JSON(steps, c.Color) case output.DriverSpew: // output the steps in spew format // diff --git a/action/step/view.go b/action/step/view.go index e26cf640..9616e5d8 100644 --- a/action/step/view.go +++ b/action/step/view.go @@ -34,7 +34,7 @@ func (c *Config) View(client *vela.Client) error { // output the step in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(step) + return output.JSON(step, c.Color) case output.DriverSpew: // output the step in spew format // diff --git a/action/worker/add.go b/action/worker/add.go index 577b483c..a778d6bf 100644 --- a/action/worker/add.go +++ b/action/worker/add.go @@ -87,7 +87,7 @@ func (c *Config) Add(client *vela.Client) error { // output the worker in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(out) + return output.JSON(out, c.Color) case output.DriverSpew: // output the worker in spew format // diff --git a/action/worker/get.go b/action/worker/get.go index e273810a..196e15c5 100644 --- a/action/worker/get.go +++ b/action/worker/get.go @@ -48,7 +48,7 @@ func (c *Config) Get(client *vela.Client) error { // output the workers in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(workers) + return output.JSON(workers, c.Color) case output.DriverSpew: // output the workers in spew format // diff --git a/action/worker/update.go b/action/worker/update.go index 9926532d..9aa42192 100644 --- a/action/worker/update.go +++ b/action/worker/update.go @@ -46,7 +46,7 @@ func (c *Config) Update(client *vela.Client) error { // output the worker in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(worker) + return output.JSON(worker, c.Color) case output.DriverSpew: // output the worker in spew format // diff --git a/action/worker/view.go b/action/worker/view.go index 99611da6..1b798926 100644 --- a/action/worker/view.go +++ b/action/worker/view.go @@ -48,7 +48,7 @@ func (c *Config) View(client *vela.Client) error { // output the worker in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(response) + return output.JSON(response, c.Color) case output.DriverSpew: // output the worker in spew format // diff --git a/command/version/version.go b/command/version/version.go index 1858df06..a48e5fb6 100644 --- a/command/version/version.go +++ b/command/version/version.go @@ -64,7 +64,7 @@ func runVersion(c *cli.Context) error { // output the version in JSON format // // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#JSON - return output.JSON(version.New()) + return output.JSON(version.New(), output.ColorOptionsFromCLIContext(c)) case output.DriverSpew: // output the version in spew format // diff --git a/internal/output/color.go b/internal/output/color.go index 3289fa4f..d7e2ca54 100644 --- a/internal/output/color.go +++ b/internal/output/color.go @@ -6,9 +6,10 @@ import ( "bytes" chroma "github.com/alecthomas/chroma/v2/quick" - "github.com/go-vela/cli/internal" "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" + + "github.com/go-vela/cli/internal" ) // ColorOptions defines the output color options used for syntax highlighting. @@ -39,16 +40,16 @@ func ColorOptionsFromCLIContext(c *cli.Context) ColorOptions { return opts } -// HighlightYAML uses chroma to highlight the provided yaml string. -func HighlightYAML(str string, opts ColorOptions) string { +// Highlight uses chroma to highlight the provided yaml string. +func Highlight(str string, lexer string, opts ColorOptions) string { if opts.Enabled { buf := new(bytes.Buffer) - err := chroma.Highlight(buf, str, "yaml", opts.Format, opts.Theme) + err := chroma.Highlight(buf, str, lexer, opts.Format, opts.Theme) if err == nil { str = buf.String() } else { - logrus.Warnf("unable to highlight yaml output: %v", err) + logrus.Warnf("unable to highlight output: %v", err) } } diff --git a/internal/output/json.go b/internal/output/json.go index 4c53bc97..b97084fe 100644 --- a/internal/output/json.go +++ b/internal/output/json.go @@ -13,7 +13,7 @@ import ( // JSON parses the provided input and // renders the parsed input in pretty // JSON before outputting it to stdout. -func JSON(_input interface{}) error { +func JSON(_input interface{}, colorOpts ColorOptions) error { logrus.Debugf("creating output with %s driver", DriverJSON) // validate the input provided @@ -30,8 +30,12 @@ func JSON(_input interface{}) error { logrus.Tracef("sending output to stdout with %s driver", DriverJSON) + // attempt to highlight the output + // returns the input and logs a warning on failure + strOutput := Highlight(string(output), "json", colorOpts) + // ensure we output to stdout - fmt.Fprintln(os.Stdout, string(output)) + fmt.Fprintln(os.Stdout, strOutput) return nil } diff --git a/internal/output/json_test.go b/internal/output/json_test.go index 3f7aa8e4..d423cf3a 100644 --- a/internal/output/json_test.go +++ b/internal/output/json_test.go @@ -49,7 +49,7 @@ func TestOutput_JSON(t *testing.T) { // run tests for _, test := range tests { - err := JSON(test.input) + err := JSON(test.input, ColorOptions{Enabled: false}) if test.failure { if err == nil { diff --git a/internal/output/yaml.go b/internal/output/yaml.go index 025a1e4d..4c392d55 100644 --- a/internal/output/yaml.go +++ b/internal/output/yaml.go @@ -32,7 +32,7 @@ func YAML(_input interface{}, colorOpts ColorOptions) error { // attempt to highlight the output // returns the input and logs a warning on failure - strOutput := HighlightYAML(string(output), colorOpts) + strOutput := Highlight(string(output), "yaml", colorOpts) // ensure we output to stdout fmt.Fprintln(os.Stdout, strOutput) From 3f701754b83fc3dfc39dfcd49f5ef9c699be3acf Mon Sep 17 00:00:00 2001 From: davidvader Date: Fri, 10 May 2024 16:52:11 -0500 Subject: [PATCH 4/5] chore: go mod tidy --- go.mod | 2 +- go.sum | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index c0304430..d95f1b9e 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.21.9 require ( github.com/Masterminds/semver/v3 v3.2.1 + github.com/alecthomas/chroma/v2 v2.13.0 github.com/buildkite/yaml v0.0.0-20230306222819-0e4e032d4835 github.com/cli/browser v1.3.0 github.com/davecgh/go-spew v1.1.1 @@ -36,7 +37,6 @@ require ( github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect github.com/PuerkitoBio/purell v1.1.1 // indirect github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect - github.com/alecthomas/chroma/v2 v2.13.0 // indirect github.com/aymerick/douceur v0.2.0 // indirect github.com/bytedance/sonic v1.9.1 // indirect github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect diff --git a/go.sum b/go.sum index 4257ad71..841fb279 100644 --- a/go.sum +++ b/go.sum @@ -18,8 +18,12 @@ github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tN github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M= github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= +github.com/alecthomas/assert/v2 v2.6.0 h1:o3WJwILtexrEUk3cUVal3oiQY2tfgr/FHWiz/v2n4FU= +github.com/alecthomas/assert/v2 v2.6.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k= github.com/alecthomas/chroma/v2 v2.13.0 h1:VP72+99Fb2zEcYM0MeaWJmV+xQvz5v5cxRHd+ooU1lI= github.com/alecthomas/chroma/v2 v2.13.0/go.mod h1:BUGjjsD+ndS6eX37YgTchSEG+Jg9Jv1GiZs9sqPqztk= +github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc= +github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8= github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= @@ -184,6 +188,8 @@ github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+l github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/hashicorp/go-retryablehttp v0.7.5 h1:bJj+Pj19UZMIweq/iie+1u5YCdGrnxCT9yvm0e+Nd5M= github.com/hashicorp/go-retryablehttp v0.7.5/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8= +github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= +github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= github.com/huandu/xstrings v1.3.3 h1:/Gcsuc1x8JVbJ9/rlye4xZnVAbEkGauT8lbebqcQws4= github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= From 381166ea46418462be5c028825d37bcb0a6f83e3 Mon Sep 17 00:00:00 2001 From: wass3rw3rk <49894298+wass3rw3rk@users.noreply.github.com> Date: Wed, 5 Jun 2024 15:28:20 -0500 Subject: [PATCH 5/5] trigger rebuild