add recur to cli
This commit is contained in:
parent
7219969010
commit
86612e4998
|
@ -18,6 +18,7 @@ var (
|
||||||
ErrFieldAlreadyUsed = errors.New("field was already used")
|
ErrFieldAlreadyUsed = errors.New("field was already used")
|
||||||
ErrInvalidDate = errors.New("could not understand date format")
|
ErrInvalidDate = errors.New("could not understand date format")
|
||||||
ErrInvalidProject = errors.New("could not understand project")
|
ErrInvalidProject = errors.New("could not understand project")
|
||||||
|
ErrInvalidRecur = errors.New("could not understand recurrer")
|
||||||
)
|
)
|
||||||
|
|
||||||
type Command interface {
|
type Command interface {
|
||||||
|
@ -124,6 +125,18 @@ func ParseTaskFieldArgs(args []string) (*task.LocalUpdate, error) {
|
||||||
fields = append(fields, task.FIELD_DUE)
|
fields = append(fields, task.FIELD_DUE)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if recur, ok := parseRecurField(f); ok {
|
||||||
|
fmt.Printf("%+v\n", recur)
|
||||||
|
if recur == nil {
|
||||||
|
return &task.LocalUpdate{}, ErrInvalidRecur
|
||||||
|
}
|
||||||
|
if lu.Recur != nil {
|
||||||
|
return &task.LocalUpdate{}, fmt.Errorf("%w: %v", ErrFieldAlreadyUsed, task.FIELD_RECUR)
|
||||||
|
}
|
||||||
|
lu.Recur = recur
|
||||||
|
fields = append(fields, task.FIELD_RECUR)
|
||||||
|
continue
|
||||||
|
}
|
||||||
if len(f) > 0 {
|
if len(f) > 0 {
|
||||||
action = append(action, f)
|
action = append(action, f)
|
||||||
}
|
}
|
||||||
|
@ -158,3 +171,15 @@ func parseDueField(s string) (task.Date, bool) {
|
||||||
|
|
||||||
return due, true
|
return due, true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseRecurField(s string) (task.Recurrer, bool) {
|
||||||
|
if !strings.HasPrefix(s, "recur:") && !strings.HasPrefix(s, "r:") {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
split := strings.SplitN(s, ":", 2)
|
||||||
|
fmt.Printf("s: %+v\n", split[1])
|
||||||
|
|
||||||
|
recur := task.NewRecurrer(split[1])
|
||||||
|
|
||||||
|
return recur, true
|
||||||
|
}
|
||||||
|
|
|
@ -90,6 +90,22 @@ func TestParseTaskFieldArgs(t *testing.T) {
|
||||||
expUpdate: &task.LocalUpdate{},
|
expUpdate: &task.LocalUpdate{},
|
||||||
expErr: command.ErrInvalidDate,
|
expErr: command.ErrInvalidDate,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "recur",
|
||||||
|
input: "recur:today,daily",
|
||||||
|
expUpdate: &task.LocalUpdate{
|
||||||
|
Fields: []string{task.FIELD_RECUR},
|
||||||
|
Recur: task.NewRecurrer("today, daily"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "recurs short",
|
||||||
|
input: "r:today,daily",
|
||||||
|
expUpdate: &task.LocalUpdate{
|
||||||
|
Fields: []string{task.FIELD_RECUR},
|
||||||
|
Recur: task.NewRecurrer("today, daily"),
|
||||||
|
},
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
args := strings.Split(tc.input, " ")
|
args := strings.Split(tc.input, " ")
|
||||||
|
|
|
@ -23,7 +23,7 @@ func NewFolder(conf *configuration.Configuration, cmdArgs []string) (*Folder, er
|
||||||
if len(cmdArgs) < 1 {
|
if len(cmdArgs) < 1 {
|
||||||
return &Folder{}, ErrInvalidAmountOfArgs
|
return &Folder{}, ErrInvalidAmountOfArgs
|
||||||
}
|
}
|
||||||
knownFolders := []string{task.FOLDER_NEW, task.FOLDER_PLANNED, task.FOLDER_UNPLANNED}
|
knownFolders := []string{task.FOLDER_NEW, task.FOLDER_RECURRING, task.FOLDER_PLANNED, task.FOLDER_UNPLANNED}
|
||||||
var folder string
|
var folder string
|
||||||
for _, f := range knownFolders {
|
for _, f := range knownFolders {
|
||||||
if strings.ToLower(f) == strings.ToLower(cmdArgs[0]) {
|
if strings.ToLower(f) == strings.ToLower(cmdArgs[0]) {
|
||||||
|
|
|
@ -24,6 +24,9 @@ func NewRecurrer(recurStr string) Recurrer {
|
||||||
}
|
}
|
||||||
|
|
||||||
terms = terms[1:]
|
terms = terms[1:]
|
||||||
|
for i, t := range terms {
|
||||||
|
terms[i] = strings.TrimSpace(t)
|
||||||
|
}
|
||||||
|
|
||||||
for _, parseFunc := range []func(Date, []string) (Recurrer, bool){
|
for _, parseFunc := range []func(Date, []string) (Recurrer, bool){
|
||||||
ParseDaily, ParseEveryNDays, ParseWeekly, ParseBiweekly,
|
ParseDaily, ParseEveryNDays, ParseWeekly, ParseBiweekly,
|
||||||
|
|
Loading…
Reference in New Issue