From 9276a3771f57d7fb9a71e53bb7bea4b55975cd46 Mon Sep 17 00:00:00 2001 From: Erik Winter Date: Mon, 18 Nov 2024 07:31:49 +0100 Subject: [PATCH] wip --- plan/command/add.go | 6 +++++- plan/command/add_test.go | 8 ++++---- plan/command/flag.go | 4 ++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/plan/command/add.go b/plan/command/add.go index 2829e68..d64d38d 100644 --- a/plan/command/add.go +++ b/plan/command/add.go @@ -47,7 +47,11 @@ func (add *AddCmd) Parse(main []string, flags map[string]string) error { as.Main = strings.Join(main[1:], " ") } for k := range as.Flags { - if err := as.Set(k, flags[k]); err != nil { + v, ok := flags[k] + if !ok { + continue + } + if err := as.Set(k, v); err != nil { return fmt.Errorf("could not set %s: %v", k, err) } } diff --git a/plan/command/add_test.go b/plan/command/add_test.go index 6a0965a..7bc196e 100644 --- a/plan/command/add_test.go +++ b/plan/command/add_test.go @@ -33,7 +33,6 @@ func TestAddParse(t *testing.T) { eventRepo := memory.NewEvent() localRepo := memory.NewLocalID() syncRepo := memory.NewSync() - cmd := command.NewAddCmd(localRepo, eventRepo, syncRepo) for _, tc := range []struct { name string main []string @@ -91,9 +90,10 @@ func TestAddParse(t *testing.T) { // }, } { t.Run(tc.name, func(t *testing.T) { - actErr := cmd.Parse(tc.main, tc.flags) - if tc.expErr != (actErr != nil) { - t.Errorf("exp nil, got %v", actErr) + cmd := command.NewAddCmd(localRepo, eventRepo, syncRepo) + actErr := cmd.Parse(tc.main, tc.flags) != nil + if tc.expErr != actErr { + t.Errorf("exp %v, got %v", tc.expErr, actErr) } }) } diff --git a/plan/command/flag.go b/plan/command/flag.go index b8ea3c5..979a1a8 100644 --- a/plan/command/flag.go +++ b/plan/command/flag.go @@ -56,7 +56,7 @@ func (ft *FlagDate) Set(val string) error { } func (ft *FlagDate) IsSet() bool { - return ft.Value.IsZero() + return !ft.Value.IsZero() } func (fs *FlagDate) Get() any { @@ -79,7 +79,7 @@ func (ft *FlagTime) Set(val string) error { } func (fd *FlagTime) IsSet() bool { - return fd.Value.IsZero() + return !fd.Value.IsZero() } func (fs *FlagTime) Get() any {