This commit is contained in:
Erik Winter 2024-11-18 07:31:49 +01:00
parent aeda0158dc
commit 9276a3771f
3 changed files with 11 additions and 7 deletions

View File

@ -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)
}
}

View File

@ -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)
}
})
}

View File

@ -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 {