Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "add --project-name" and check for exactly one positional argument #253

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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