From a680bb800234af4ca4a27303bdbddf133859678c Mon Sep 17 00:00:00 2001 From: Volker Schukai <volker.schukai@schukai.com> Date: Fri, 23 Dec 2022 11:04:51 +0100 Subject: [PATCH] fix: handle values from type flags.Bool --- help_test.go | 6 +++--- mapping.go | 2 +- type.go | 7 +++++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/help_test.go b/help_test.go index 7d0a6dd..8508a5c 100644 --- a/help_test.go +++ b/help_test.go @@ -32,9 +32,9 @@ func TestGetHelp(t *testing.T) { args []string substring string }{ - {"test1", []string{"sub1", "--help"}, "Usage: test1 sub1 [global options] [command] [arguments]"}, - {"test1", []string{"xsd", "help"}, "Usage: test1 [global options] [command] [arguments]"}, - {"test2", []string{"sub1", "sub2"}, "Usage: test2 sub1 sub2 [global options] [command] [arguments]"}, + {"test1", []string{"sub1", "--help"}, "Usage: [global options] [command] [arguments]\n\nGlobal Options:\n -a\tMessage A\n -x int\n \tMessage X\n\nCommand: sub1\n\nOptions:\n -b\tMessage B\n"}, + {"test1", []string{"xsd", "help"}, "Usage: [global options] [command] [arguments]\n\nGlobal Options:\n -a\tMessage A\n -x int\n \tMessage X\n\nCommand: sub1\n\nOptions:\n -b\tMessage B\n"}, + {"test2", []string{"sub1", "sub2"}, "Usage: [global options] [command] [arguments]\n\nGlobal Options:\n -a\tMessage A\n -x int\n \tMessage X\n\nCommand: sub1\n\nOptions:\n -b\tMessage B\n"}, } for _, table := range tables { diff --git a/mapping.go b/mapping.go index 296973d..19a0b66 100644 --- a/mapping.go +++ b/mapping.go @@ -37,7 +37,7 @@ func (s *Settings[C]) assignValues(c cmd[C]) { flgs.Visit(func(f *flag.Flag) { name := f.Name - value := f.Value //.String() + value := f.Value.String() k, ok := c.tagMapping[name] if !ok { diff --git a/type.go b/type.go index 48172c4..c03332a 100644 --- a/type.go +++ b/type.go @@ -1,6 +1,9 @@ package xflags -import "strings" +import ( + "fmt" + "strings" +) type StringFlags []string @@ -18,7 +21,7 @@ type IntFlags []int func (i *IntFlags) String() string { r := make([]string, len(*i)) for k, v := range *i { - r[k] = string(v) + r[k] = fmt.Sprintf("%c", v) } return strings.Join(r, ",") -- GitLab