diff --git a/cmd/new.go b/cmd/new.go index 9105037..50bfbda 100644 --- a/cmd/new.go +++ b/cmd/new.go @@ -50,18 +50,17 @@ to quickly create a Cobra application.`, Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { dateString, err := cmd.Flags().GetString("due") - if err != nil { - log.Fatal(err) - } - createTodo(strings.Join(args, " "), dateString) - // fmt.Println(time.Parse("02/01/2006T15:04", t)) - // fmt.Println(time.Parse("02/01/2006", t)) + errPanic(err, "") + comp, err := cmd.Flags().GetBool("complete") + errPanic(err, "") + createTodo(strings.Join(args, " "), dateString, comp) }, } func init() { rootCmd.AddCommand(newCmd) newCmd.Flags().StringP("due", "d", "", "due date") + newCmd.Flags().BoolP("complete", "c", false, "mark todo as completed") // Here you will define your flags and configuration settings. diff --git a/cmd/todo.go b/cmd/todo.go index c00c668..b5bf6cd 100644 --- a/cmd/todo.go +++ b/cmd/todo.go @@ -48,13 +48,13 @@ func openDB() *gorm.DB { return db } -func createTodo(desc string, date string) { +func createTodo(desc string, date string, comp bool) { db := openDB() err := db.AutoMigrate(&Todo{}) errPanic(err, "failed to migrate database") d := parseDateString(date) - t := Todo{Desc: desc, DueDate: d, CreatedAt: time.Now(), IsDone: false} + t := Todo{Desc: desc, DueDate: d, CreatedAt: time.Now(), IsDone: comp} db.Create(&t) }