Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
1fff23f
add no-color support for atmos
samtholiya Apr 30, 2025
4cd8889
fix test case error
samtholiya Apr 30, 2025
896b4ef
fix test case
samtholiya May 1, 2025
d7c7fc6
fix tests
samtholiya May 1, 2025
59964b0
Merge branch 'main' into feature/dev-3177--no-color-should-be-a-globa…
samtholiya May 1, 2025
5f5cab2
removed editorconfig color parameter
samtholiya May 1, 2025
e38d2e4
Merge branch 'feature/dev-3177--no-color-should-be-a-global-flag' of …
samtholiya May 1, 2025
159ac32
fixed test case
samtholiya May 1, 2025
6d28396
configuration refactor
samtholiya May 1, 2025
5bf115e
add test case for color vs no-color
samtholiya May 1, 2025
cd8d695
[autofix.ci] apply automated fixes
autofix-ci[bot] May 1, 2025
139ffb4
added test for no color
samtholiya May 1, 2025
3e82d10
Merge branch 'feature/dev-3177--no-color-should-be-a-global-flag' of …
samtholiya May 1, 2025
d1b9045
added tests
samtholiya May 1, 2025
14534fb
fix logging render
samtholiya May 1, 2025
31aff06
fix lint
samtholiya May 1, 2025
61e1c7f
fix exception
samtholiya May 1, 2025
2bf2e0b
fix tests
samtholiya May 1, 2025
8737e9d
fix tests
samtholiya May 1, 2025
a0890d6
add test coverage
samtholiya May 1, 2025
b7fc01b
add more test coverage
samtholiya May 1, 2025
c832868
try fix
samtholiya May 2, 2025
d05600e
revert support test to check windows
samtholiya May 4, 2025
31e182c
configuration markdown update
samtholiya May 4, 2025
08f3dc1
added more test case
samtholiya May 4, 2025
8f70892
fix test case
samtholiya May 4, 2025
d6a02ed
revert the change
samtholiya May 4, 2025
6aff052
add logs to the test
samtholiya May 4, 2025
de270f7
added more logs
samtholiya May 4, 2025
131249b
check this
samtholiya May 4, 2025
feb782c
test windows check
samtholiya May 4, 2025
992c98b
support test case added
samtholiya May 4, 2025
39bbe6c
added documentation
samtholiya May 5, 2025
efd3bf7
Merge branch 'main' into feature/dev-3177--no-color-should-be-a-globa…
samtholiya May 8, 2025
7a5c193
Fix code rabbit comment
samtholiya May 9, 2025
3cc559b
Merge branch 'main' into feature/dev-3177--no-color-should-be-a-globa…
samtholiya May 9, 2025
f6742a1
Merge branch 'main' into feature/dev-3177--no-color-should-be-a-globa…
Benbentwo May 14, 2025
ba10aad
[autofix.ci] apply automated fixes
autofix-ci[bot] May 14, 2025
765da27
update tests
Benbentwo May 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@ settings:
terminal:
max_width: 120 # Maximum width for terminal output
pager: true # Pager setting for all terminal output
colors: true # Enable colored output
unicode: true # Use unicode characters

syntax_highlighting:
Expand Down
12 changes: 12 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"regexp"
"strings"

"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/log"
"github.com/elewis787/boa"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -95,6 +96,16 @@ func setupLogger(atmosConfig *schema.AtmosConfiguration) {
log.SetLevel(log.InfoLevel)
}

if atmosConfig.Settings.Terminal.NoColor {
stylesDefault := log.DefaultStyles()
// Clear colors for levels
styles := &log.Styles{}
styles.Levels = make(map[log.Level]lipgloss.Style)
for k := range stylesDefault.Levels {
styles.Levels[k] = stylesDefault.Levels[k].UnsetForeground().Bold(false)
}
log.SetStyles(styles)
}
var output io.Writer

switch atmosConfig.Logs.File {
Expand Down Expand Up @@ -194,6 +205,7 @@ func init() {
RootCmd.PersistentFlags().String("base-path", "", "Base path for Atmos project")
RootCmd.PersistentFlags().StringSlice("config", []string{}, "Paths to configuration files (comma-separated or repeated flag)")
RootCmd.PersistentFlags().StringSlice("config-path", []string{}, "Paths to configuration directories (comma-separated or repeated flag)")
RootCmd.PersistentFlags().Bool("no-color", false, "Disable color output")
// Set custom usage template
err := templates.SetCustomUsageFunc(RootCmd)
if err != nil {
Expand Down
37 changes: 37 additions & 0 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package cmd

import (
"bytes"
"os"
"strings"
"testing"

log "github.com/charmbracelet/log"
)

func TestNoColorLog(t *testing.T) {
// Set the environment variable to disable color
// t.Setenv("NO_COLOR", "1")
t.Setenv("ATMOS_LOGS_LEVEL", "Debug")
t.Setenv("NO_COLOR", "1")
// Create a buffer to capture the output
var buf bytes.Buffer
log.SetOutput(&buf)

oldArgs := os.Args
defer func() {
os.Args = oldArgs
}()
// Set the arguments for the command
os.Args = []string{"atmos", "about"}
// Execute the command
if err := Execute(); err != nil {
t.Fatalf("Failed to execute command: %v", err)
}
// Check if the output is without color
output := buf.String()
if strings.Contains(output, "\033[") {
t.Errorf("Expected no color in output, but got: %s", output)
}
t.Log(output, "output")
}
35 changes: 0 additions & 35 deletions cmd/support_test.go

This file was deleted.

7 changes: 4 additions & 3 deletions cmd/validate_editorconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@
cliConfig.Verbose = true
}
}
if !cmd.Flags().Changed("no-color") && !atmosConfig.Validate.EditorConfig.Color {
cliConfig.NoColor = !atmosConfig.Validate.EditorConfig.Color
if !cmd.Flags().Changed("no-color") && atmosConfig.Settings.Terminal.NoColor {
cliConfig.NoColor = atmosConfig.Settings.Terminal.NoColor

Check warning on line 120 in cmd/validate_editorconfig.go

View check run for this annotation

Codecov / codecov/patch

cmd/validate_editorconfig.go#L120

Added line #L120 was not covered by tests
} else if cmd.Flags().Changed("no-color") {
cliConfig.NoColor, _ = cmd.Flags().GetBool("no-color")

Check warning on line 122 in cmd/validate_editorconfig.go

View check run for this annotation

Codecov / codecov/patch

cmd/validate_editorconfig.go#L122

Added line #L122 was not covered by tests
}
if !cmd.Flags().Changed("disable-trim-trailing-whitespace") && atmosConfig.Validate.EditorConfig.DisableTrimTrailingWhitespace {
cliConfig.Disable.TrimTrailingWhitespace = atmosConfig.Validate.EditorConfig.DisableTrimTrailingWhitespace
Expand Down Expand Up @@ -192,7 +194,6 @@
cmd.PersistentFlags().BoolVar(&cliConfig.DryRun, "dry-run", false, "Show which files would be checked")
cmd.PersistentFlags().BoolVar(&cliConfig.ShowVersion, "version", false, "Print the version number")
cmd.PersistentFlags().StringVar(&format, "format", "default", "Specify the output format: default, gcc")
cmd.PersistentFlags().BoolVar(&cliConfig.NoColor, "no-color", false, "Don't print colors")
cmd.PersistentFlags().BoolVar(&cliConfig.Disable.TrimTrailingWhitespace, "disable-trim-trailing-whitespace", false, "Disable trailing whitespace check")
cmd.PersistentFlags().BoolVar(&cliConfig.Disable.EndOfLine, "disable-end-of-line", false, "Disable end-of-line check")
cmd.PersistentFlags().BoolVar(&cliConfig.Disable.InsertFinalNewline, "disable-insert-final-newline", false, "Disable final newline check")
Expand Down
5 changes: 5 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@
if v, ok := flagKeyValue["logs-file"]; ok {
atmosConfig.Logs.File = v
}
if flagKeyValue, ok := flagKeyValue["no-color"]; ok || flagKeyValue == "true" {
atmosConfig.Settings.Terminal.NoColor = true
} else if flagKeyValue == "false" {
atmosConfig.Settings.Terminal.NoColor = false
}

Check warning on line 84 in pkg/config/config.go

View check run for this annotation

Codecov / codecov/patch

pkg/config/config.go#L83-L84

Added lines #L83 - L84 were not covered by tests
}

// TODO: This function works well, but we should generally avoid implementing manual flag parsing,
Expand Down
83 changes: 83 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,3 +403,86 @@ func TestMergeDefaultConfig(t *testing.T) {
err = mergeDefaultConfig(v)
assert.NoError(t, err, "should not return error if config type is yaml")
}

func TestParseFlags(t *testing.T) {
tests := []struct {
name string
args []string
expected map[string]string
}{
{
name: "no flags",
args: []string{},
expected: map[string]string{},
},
{
name: "single flag",
args: []string{"--key=value"},
expected: map[string]string{"key": "value"},
},
{
name: "multiple flags",
args: []string{"--key1=value1", "--key2=value2"},
expected: map[string]string{"key1": "value1", "key2": "value2"},
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
oldArgs := os.Args
defer func() { os.Args = oldArgs }()
os.Args = test.args
result := parseFlags()
assert.Equal(t, test.expected, result)
})
}
}

func TestSetLogConfig(t *testing.T) {
tests := []struct {
name string
args []string
expectedLogLevel string
expectetdNoColor bool
}{
{
name: "valid log level",
args: []string{"--logs-level", "Debug"},
expectedLogLevel: "Debug",
},
{
name: "invalid log level",
args: []string{"--logs-level", "InvalidLevel"},
expectedLogLevel: "InvalidLevel",
},
{
name: "No color flag",
args: []string{"--no-color"},
expectedLogLevel: "",
expectetdNoColor: true,
},
{
name: "No color flag with log level",
args: []string{"--no-color", "--logs-level", "Debug"},
expectedLogLevel: "Debug",
expectetdNoColor: true,
},
{
name: "No color flag disable with log level",
args: []string{"--no-color=false", "--logs-level", "Debug"},
expectedLogLevel: "Debug",
expectetdNoColor: false,
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
oldArgs := os.Args
defer func() { os.Args = oldArgs }()
os.Args = test.args
atmosConfig := &schema.AtmosConfiguration{}
setLogConfig(atmosConfig)
assert.Equal(t, test.expectedLogLevel, atmosConfig.Logs.Level)
})
}
}
1 change: 0 additions & 1 deletion pkg/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ var (
Terminal: schema.Terminal{
MaxWidth: templates.GetTerminalWidth(),
Pager: "less",
Colors: true,
Unicode: true,
SyntaxHighlighting: schema.SyntaxHighlighting{
Enabled: true,
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ func LoadConfig(configAndStacksInfo *schema.ConfigAndStacksInfo) (schema.AtmosCo
}
}
setEnv(v)
// We want the editorconfig color by default to be true
atmosConfig.Validate.EditorConfig.Color = true
// https://gist.github.com/chazcheadle/45bf85b793dea2b71bd05ebaa3c28644
// https://sagikazarmark.hu/blog/decoding-custom-formats-with-viper/
err := v.Unmarshal(&atmosConfig)
Expand All @@ -101,6 +99,7 @@ func setEnv(v *viper.Viper) {
bindEnv(v, "settings.atmos_gitlab_token", "ATMOS_GITLAB_TOKEN")

bindEnv(v, "settings.terminal.pager", "ATMOS_PAGER", "PAGER")
bindEnv(v, "settings.terminal.no_color", "ATMOS_NO_COLOR", "NO_COLOR")
}

func bindEnv(v *viper.Viper, key ...string) {
Expand All @@ -118,6 +117,7 @@ func setDefaultConfiguration(v *viper.Viper) {
v.SetDefault("logs.file", "/dev/stderr")
v.SetDefault("logs.level", "Info")

v.SetDefault("settings.terminal.no_color", false)
v.SetDefault("settings.terminal.pager", true)
v.SetDefault("docs.generate.readme.output", "./README.md")
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ type EditorConfig struct {
IgnoreDefaults bool `yaml:"ignore_defaults,omitempty" json:"ignore_defaults,omitempty" mapstructure:"ignore_defaults"`
DryRun bool `yaml:"dry_run,omitempty" json:"dry_run,omitempty" mapstructure:"dry_run"`
Format string `yaml:"format,omitempty" json:"format,omitempty" mapstructure:"format"`
Color bool `yaml:"color,omitempty" json:"color,omitempty" mapstructure:"color"`
ConfigFilePaths []string `yaml:"config_file_paths,omitempty" json:"config_file_paths,omitempty" mapstructure:"config_file_paths"`
Exclude []string `yaml:"exclude,omitempty" json:"exclude,omitempty" mapstructure:"exclude"`
Init bool `yaml:"init,omitempty" json:"init,omitempty" mapstructure:"init"`
Expand All @@ -190,9 +189,9 @@ type EditorConfig struct {
type Terminal struct {
MaxWidth int `yaml:"max_width" json:"max_width" mapstructure:"max_width"`
Pager string `yaml:"pager" json:"pager" mapstructure:"pager"`
Colors bool `yaml:"colors" json:"colors" mapstructure:"colors"`
Unicode bool `yaml:"unicode" json:"unicode" mapstructure:"unicode"`
SyntaxHighlighting SyntaxHighlighting `yaml:"syntax_highlighting" json:"syntax_highlighting" mapstructure:"syntax_highlighting"`
NoColor bool `yaml:"no_color" json:"no_color" mapstructure:"no_color"`
}

func (t *Terminal) IsPagerEnabled() bool {
Expand Down
Loading
Loading