Skip to content

Commit a8d1d6e

Browse files
committed
Sort log levels alphabetically; update test snapshots
1 parent 3a53501 commit a8d1d6e

3 files changed

+11
-3
lines changed

pkg/logger/logger.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"io"
77
"os"
8+
"sort"
89
"strings"
910

1011
"github.com/charmbracelet/lipgloss"
@@ -134,7 +135,14 @@ func ParseLogLevel(logLevel string) (log.Level, error) {
134135
return level, nil
135136
}
136137

137-
validLevels := []string{"Trace", "Debug", "Info", "Warning", "Off"}
138+
// Extract the keys from LogLevelStrings map to avoid redundancy
139+
var validLevels []string
140+
for k := range LogLevelStrings {
141+
validLevels = append(validLevels, k)
142+
}
143+
144+
// Sort the levels alphabetically to ensure consistent output
145+
sort.Strings(validLevels)
138146

139147
return 0, fmt.Errorf("%w `%s`. Valid options are: %v", ErrInvalidLogLevel, logLevel, validLevels)
140148
}

tests/snapshots/TestCLICommands_Invalid_Log_Level_in_Config_File.stderr.golden

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/snapshots/TestCLICommands_Invalid_Log_Level_in_Environment_Variable.stderr.golden

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)