Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

enhance: syntax highlighting for json/yaml #558

Merged
merged 6 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions action/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -17,4 +19,5 @@ type Config struct {
Page int
PerPage int
Output string
Color output.ColorOptions
}
4 changes: 2 additions & 2 deletions action/build/cancel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand All @@ -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
//
Expand Down
4 changes: 2 additions & 2 deletions action/build/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions action/build/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand All @@ -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
//
Expand Down
4 changes: 2 additions & 2 deletions action/build/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand All @@ -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
//
Expand Down
3 changes: 3 additions & 0 deletions action/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -22,4 +24,5 @@ type Config struct {
UpdateFlags map[string]string
RemoveFlags []string
Output string
Color output.ColorOptions
}
15 changes: 15 additions & 0 deletions action/config/empty.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,21 @@ 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
Expand Down
19 changes: 11 additions & 8 deletions action/config/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions action/config/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
45 changes: 45 additions & 0 deletions action/config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,51 @@
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)

Check failure on line 203 in action/config/load.go

View workflow job for this annotation

GitHub Actions / diff-review

assignments should only be cuddled with other assignments (wsl)

Check failure on line 203 in action/config/load.go

View workflow job for this annotation

GitHub Actions / diff-review

assignments should only be cuddled with other assignments (wsl)

Check failure on line 203 in action/config/load.go

View workflow job for this annotation

GitHub Actions / full-review

assignments should only be cuddled with other assignments (wsl)

Check failure on line 203 in action/config/load.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] action/config/load.go#L203

assignments should only be cuddled with other assignments (wsl)
Raw output
action/config/load.go:203:4: assignments should only be cuddled with other assignments (wsl)
			err = ctx.Set(internal.FlagColor, c)
			^
plyr4 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {

Check failure on line 204 in action/config/load.go

View workflow job for this annotation

GitHub Actions / diff-review

only one cuddle assignment allowed before if statement (wsl)

Check failure on line 204 in action/config/load.go

View workflow job for this annotation

GitHub Actions / diff-review

only one cuddle assignment allowed before if statement (wsl)

Check failure on line 204 in action/config/load.go

View workflow job for this annotation

GitHub Actions / full-review

only one cuddle assignment allowed before if statement (wsl)

Check failure on line 204 in action/config/load.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] action/config/load.go#L204

only one cuddle assignment allowed before if statement (wsl)
Raw output
action/config/load.go:204:4: only one cuddle assignment allowed before if statement (wsl)
			if err != nil {
			^
plyr4 marked this conversation as resolved.
Show resolved Hide resolved
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) &&
Expand Down
18 changes: 18 additions & 0 deletions action/config/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
)

// Remove deletes one or more fields from the config file based off the provided configuration.
func (c *Config) Remove() error {

Check failure on line 16 in action/config/remove.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] action/config/remove.go#L16

Function 'Remove' is too long (165 > 160) (funlen)
Raw output
action/config/remove.go:16: Function 'Remove' is too long (165 > 160) (funlen)
func (c *Config) Remove() error {
logrus.Debug("executing remove for config file configuration")

// use custom filesystem which enables us to test
Expand Down Expand Up @@ -143,6 +143,24 @@
// 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")
Expand Down
23 changes: 23 additions & 0 deletions action/config/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions action/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -17,4 +19,5 @@ type Config struct {
DropAdmins []string
Full bool
Output string
Color output.ColorOptions
}
4 changes: 2 additions & 2 deletions action/dashboard/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand All @@ -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
//
Expand Down
4 changes: 2 additions & 2 deletions action/deployment/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand All @@ -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
//
Expand Down
6 changes: 5 additions & 1 deletion action/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -18,5 +21,6 @@ type Config struct {
Page int
PerPage int
Output string
Color output.ColorOptions
Parameters raw.StringSliceMap
}
4 changes: 2 additions & 2 deletions action/deployment/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions action/deployment/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand All @@ -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
//
Expand Down
Loading
Loading