Skip to content

Commit

Permalink
Fix logging in editor_config
Browse files Browse the repository at this point in the history
  • Loading branch information
samtholiya committed Dec 28, 2024
1 parent 80feea2 commit 6ae752b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
22 changes: 9 additions & 13 deletions cmd/editor_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"os"

"github.com/cloudposse/atmos/pkg/schema"
u "github.com/cloudposse/atmos/pkg/utils"

"github.com/editorconfig-checker/editorconfig-checker/v3/pkg/config"
Expand All @@ -25,9 +24,9 @@ var (
)

var editorConfigCmd *cobra.Command = &cobra.Command{
Use: "editorconfig-checker",
Short: "EditorConfig Checker CLI",
Long: "A command-line tool to check your files against the EditorConfig rules",
Use: "editorconfig",
Short: "Validate all files against the EditorConfig",
Long: "Validate all files against the project's EditorConfig rules",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
initializeConfig()
},
Expand All @@ -38,7 +37,7 @@ var editorConfigCmd *cobra.Command = &cobra.Command{

// initializeConfig breaks the initialization cycle by separating the config setup
func initializeConfig() {
u.LogInfo(schema.AtmosConfiguration{}, fmt.Sprintf("EditorConfig Checker CLI Version: %s", editorConfigVersion))
u.LogInfo(atmosConfig, fmt.Sprintf("EditorConfig Checker CLI Version: %s", editorConfigVersion))
if configFilePath == "" {
configFilePath = defaultConfigFilePath
}
Expand Down Expand Up @@ -67,8 +66,7 @@ func runMainLogic() {

if utils.FileExists(config.Path) && config.Version != "" && config.Version != editorConfigVersion {
u.LogError(atmosConfig, fmt.Errorf("Version from config file is not the same as the version of the binary"))
u.LogError(atmosConfig, fmt.Errorf("Binary: %s, Config: %s", editorConfigVersion, config.Version))
os.Exit(1)
u.LogErrorAndExit(atmosConfig, fmt.Errorf("Binary: %s, Config: %s", editorConfigVersion, config.Version))
}

if handleReturnableFlags(config) {
Expand All @@ -77,8 +75,7 @@ func runMainLogic() {

filePaths, err := files.GetFiles(config)
if err != nil {
u.LogError(atmosConfig, err)
os.Exit(1)
u.LogErrorAndExit(atmosConfig, err)
}

if config.DryRun {
Expand All @@ -93,12 +90,11 @@ func runMainLogic() {

if errorCount != 0 {
er.PrintErrors(errors, config)
u.LogError(atmosConfig, fmt.Errorf("\n%d errors found", errorCount))
os.Exit(1)
u.LogErrorAndExit(atmosConfig, fmt.Errorf("\n%d errors found", errorCount))
}

u.LogTrace(atmosConfig, fmt.Sprintf("%d files checked", len(filePaths)))
u.LogInfo(schema.AtmosConfiguration{}, "No errors found")
u.LogDebug(atmosConfig, fmt.Sprintf("%d files checked", len(filePaths)))
u.LogInfo(atmosConfig, "No errors found")
}

// handleReturnableFlags handles early termination flags
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions tests/test_cases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ tests:
- name: atmos validate editorconfig-check
enabled: true
description: "Ensure atmos CLI validates based on the .ecrc file."
workdir: "../examples/demo-stacks/"
workdir: "../examples/quick-start-simple/"
command: "atmos"
args:
- "validate"
- "editorconfig-checker"
- "editorconfig"
expect:
stdout:
- "EditorConfig Checker CLI Version: v3.0.0"
Expand Down

0 comments on commit 6ae752b

Please sign in to comment.