Skip to content

Commit

Permalink
Merge pull request #253 from mgsloan/fix-add-project-name
Browse files Browse the repository at this point in the history
Fix "add --project-name" and check for exactly one positional argument
  • Loading branch information
sachaos authored Oct 18, 2024
2 parents 7d31f4b + 2a33438 commit e727ab0
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions add.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"fmt"
"strings"

"github.com/sachaos/todoist/lib"
Expand All @@ -19,16 +20,25 @@ func Add(c *cli.Context) error {
client := GetClient(c)

item := todoist.Item{}
if !c.Args().Present() {
return CommandFailed
if c.Args().Len() != 1 {
return fmt.Errorf("add command requires 1 positional argument for the task title, but got %v.", c.Args().Len())
}

item.Content = c.Args().First()

item.Priority = priorityMapping[c.Int("priority")]
item.ProjectID = c.String("project-id")
if item.ProjectID == "" {
item.ProjectID = client.Store.Projects.GetIDByName(c.String("project-name"))

projectName := c.String("project-name")
if projectName != "" {
projectId := client.Store.Projects.GetIDByName(projectName)
if projectId == "" {
return fmt.Errorf("Did not find a project named '%v'", projectName)
}
item.ProjectID = projectId
} else {
item.ProjectID = c.String("project-id")
}

item.LabelNames = func(str string) []string {
stringNames := strings.Split(str, ",")
names := []string{}
Expand Down

0 comments on commit e727ab0

Please sign in to comment.