From eea9593ad50be07e54fb852a91c884298f923ac3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9=20=D0=91=D0=B0?= =?UTF-8?q?=D0=B4=D1=8F=D0=B5=D0=B2?= Date: Thu, 24 Oct 2024 17:58:16 +0700 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D0=BF=D0=BE=D0=B2=D1=82=D0=BE=D1=80=D0=BD?= =?UTF-8?q?=D0=BE=D0=B5=20=D0=BE=D0=BF=D1=80=D0=B5=D0=B4=D0=B5=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=84=D0=BB=D0=B0=D0=B3=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cli.go | 1 + cli_test.go | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) 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) +}