wip
This commit is contained in:
parent
aeb8e3d741
commit
b7da3fba1e
|
@ -44,15 +44,12 @@ func (add *AddCmd) Parse(args []string) (*ArgSet, error) {
|
|||
if !as.HasFlag(FlagOn) {
|
||||
return nil, fmt.Errorf("%w: date is required", ErrInvalidArg)
|
||||
}
|
||||
if !as.HasFlag(FlagAt) && !as.HasFlag(FlagFor) {
|
||||
if !as.HasFlag(FlagAt) && as.HasFlag(FlagFor) {
|
||||
return nil, fmt.Errorf("%w: can not have duration without start time", ErrInvalidArg)
|
||||
}
|
||||
if !as.HasFlag(FlagAt) && !as.HasFlag(FlagFor) {
|
||||
as.SetFlag(FlagFor, "24h")
|
||||
}
|
||||
if err := add.Do(as); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return as, nil
|
||||
}
|
||||
|
|
|
@ -1,5 +1,77 @@
|
|||
package command_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"go-mod.ewintr.nl/planner/plan/command"
|
||||
)
|
||||
|
||||
func TestAddParse(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
cmd := command.AddCmd{}
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
args []string
|
||||
expAS *command.ArgSet
|
||||
expErr bool
|
||||
}{
|
||||
{
|
||||
name: "empty",
|
||||
expErr: true,
|
||||
},
|
||||
{
|
||||
name: "title missing",
|
||||
args: []string{"add", "-on", "2024-11-09"},
|
||||
expErr: true,
|
||||
},
|
||||
{
|
||||
name: "date missing",
|
||||
args: []string{"add", "some", "title"},
|
||||
expErr: true,
|
||||
},
|
||||
{
|
||||
name: "minimal",
|
||||
args: []string{"add", "title", "-on", "2024-11-09"},
|
||||
expAS: &command.ArgSet{
|
||||
Main: "title",
|
||||
Flags: map[string]string{
|
||||
command.FlagOn: "2024-11-09",
|
||||
command.FlagFor: "24h",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "start",
|
||||
args: []string{"add", "title", "-on", "2024-11-09", "-at", "12:00"},
|
||||
expAS: &command.ArgSet{
|
||||
Main: "title",
|
||||
Flags: map[string]string{
|
||||
command.FlagOn: "2024-11-09",
|
||||
command.FlagAt: "12:00",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
// name: "start and duration"
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
actAS, actErr := cmd.Parse(tc.args)
|
||||
if tc.expErr != (actErr != nil) {
|
||||
t.Errorf("exp nil, got %v", actErr)
|
||||
}
|
||||
if tc.expErr {
|
||||
return
|
||||
}
|
||||
if diff := cmp.Diff(tc.expAS, actAS); diff != "" {
|
||||
t.Errorf("(exp +, got -)\n%s", diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// func TestAdd(t *testing.T) {
|
||||
// t.Parallel()
|
||||
|
||||
|
|
Loading…
Reference in New Issue