Skip to content

Commit

Permalink
feat(go): allow completing multiple tasks at once
Browse files Browse the repository at this point in the history
  • Loading branch information
milanmlft committed Oct 22, 2024
1 parent a76453f commit ef33f8b
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions todo-go/cmd/done.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ import (
// doneCmd represents the done command
var doneCmd = &cobra.Command{
Use: "done [task ID]",
Short: "Mark a task as done",
Long: `Set the status of the given task to done`,
Short: "Mark tasks as done",
Long: `Set the status of the given tasks to done`,
Args: cobra.MinimumNArgs(1),
Run: doneRun,
}

func init() {
rootCmd.AddCommand(doneCmd)
doneCmd.PersistentFlags().BoolP("verbose", "v", false,
"Verbosity, whether to print task list after adding")
"Verbosity, whether to print task list after completing")
}

func doneRun(cmd *cobra.Command, args []string) {
Expand All @@ -30,13 +30,16 @@ func doneRun(cmd *cobra.Command, args []string) {
log.Fatalf("Failed to read todos from database with `%v`", err)
}

id, err := strconv.Atoi(args[0])
if err != nil {
log.Fatalln(args[0], "is not a valid ID\n", err)
}
err = todos.Complete(id)
if err != nil {
log.Fatalf("Error: %v", err)
for _, arg := range args {
id, err := strconv.Atoi(arg)
if err != nil {
log.Fatalln(arg, "is not a valid ID\n", err)
}
err = todos.Complete(id)
if err != nil {
log.Fatalf("Error for arg %s: %v", arg, err)
}

}
db.WriteTodos(todos)

Expand Down

0 comments on commit ef33f8b

Please sign in to comment.