diff --git a/cmd/rm.go b/cmd/rm.go index 93cf81c..ac8f306 100644 --- a/cmd/rm.go +++ b/cmd/rm.go @@ -29,9 +29,13 @@ var rmCmd = &cobra.Command{ Long: `Remove a todo given its id.`, Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - id, err := strconv.ParseUint(args[0], 10, 0) - errPanic(err, "failed to parse uint") - deleteTodo(id) + var ids []uint64 + for _, arg := range args { + id, err := strconv.ParseUint(arg, 10, 0) + errPanic(err, "failed to parse uint") + ids = append(ids, id) + } + deleteTodo(ids) }, } diff --git a/cmd/todo.go b/cmd/todo.go index d73dd4d..33c99c4 100644 --- a/cmd/todo.go +++ b/cmd/todo.go @@ -45,7 +45,7 @@ func parseDateString(date string) time.Time { // openDB returns gorm database. func openDB() *gorm.DB { - db, err := gorm.Open(sqlite.Open("todo.db"), &gorm.Config{}) + db, err := gorm.Open(sqlite.Open("/home/user/.todo.db"), &gorm.Config{}) errPanic(err, "failed to connect database") return db @@ -82,9 +82,11 @@ func updateTodo(id uint64, desc string, date string, comp bool) { } // deleteTodo deletes an entry of id todo in the database. -func deleteTodo(id uint64) { +func deleteTodo(ids []uint64) { db := openDB() - db.Delete(&Todo{}, id) + for _, id := range ids { + db.Delete(&Todo{}, id) + } } // getAllTodos return all todos from the database.