diff --git a/cmd/rm.go b/cmd/rm.go index 9b6b049..ba0b494 100644 --- a/cmd/rm.go +++ b/cmd/rm.go @@ -17,7 +17,7 @@ along with this program. If not, see . package cmd import ( - "fmt" + "strconv" "github.com/spf13/cobra" ) @@ -32,8 +32,11 @@ and usage of using your command. For example: Cobra is a CLI library for Go that empowers applications. This application is a tool to generate the needed files to quickly create a Cobra application.`, + Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - fmt.Println("rm called") + id, err := strconv.ParseUint(args[0], 10, 0) + errPanic(err, "failed to parse uint") + deleteTodo(id) }, } diff --git a/cmd/todo.go b/cmd/todo.go index 5e03ade..8e8de08 100644 --- a/cmd/todo.go +++ b/cmd/todo.go @@ -55,7 +55,7 @@ func createTodo(desc string, date string) { db.Create(&t) } -func updateTodo(id uint, new Todo) { +func updateTodo(id uint64, new Todo) { db := openDB() var t Todo res := db.First(&t, id) @@ -64,7 +64,7 @@ func updateTodo(id uint, new Todo) { db.Model(&t).Updates(new) } -func deleteTodo(id uint) { +func deleteTodo(id uint64) { db := openDB() db.Delete(&Todo{}, id) }