diff --git a/cli.go b/cli.go index f52c383..10fd38b 100644 --- a/cli.go +++ b/cli.go @@ -313,6 +313,7 @@ func (c *Command) addFlag(value reflect.Value, field reflect.StructField) error return ErrInternalError }, ) + return nil } kind := value.Kind() diff --git a/cli_test.go b/cli_test.go index 40cf3e7..307b5e8 100644 --- a/cli_test.go +++ b/cli_test.go @@ -17,6 +17,7 @@ package config import ( "flag" + "log/slog" "os" "strconv" "testing" @@ -299,3 +300,20 @@ func TestDurationWithEqual(t *testing.T) { assert.NoError(cmd.Parse(cmd.Args)) assert.Equal(time.Second*5, conf.interval) } + +func TestLogLevel(t *testing.T) { + assert := assert.New(t) + var conf struct { + Level slog.Level `cli:"log-level" default:"INFO"` + } + + cmd := NewCLI("Config") + assert.NoError(cmd.Init(&conf), "init config command") + + args := []string{"-v", "-log-level", "DEBUG", "help"} + + assert.ElementsMatch([]string{"-v", "help"}, cmd.Capture(args)) + assert.ElementsMatch([]string{"-log-level", "DEBUG"}, cmd.Args) + assert.NoError(cmd.Parse(cmd.Args)) + assert.Equal(slog.LevelDebug, conf.Level) +}