/* Copyright © 2021 NAME HERE */ package cmd import ( "fmt" "log" "strconv" "github.com/spf13/cobra" ) // showCmd represents the show command var showCmd = &cobra.Command{ Use: "show", Args: cobra.ExactArgs(1), Short: "Display a diary entry and its notes", Long: `Display a diary entry and its notes. To disable markdown rendering in the output, pass the --no-markdown flag (WIP) $ diary show 2 --no-markdown `, PreRunE: func(cmd *cobra.Command, args []string) error { id, err := strconv.Atoi(args[0]) if err != nil { return err } _, err = App.Db.GetDiaryEntry(int64(id)) if err != nil { return err } return nil }, Run: func(cmd *cobra.Command, args []string) { entry_id, _ := strconv.Atoi(args[0]) var entry, err = App.Db.GetDiaryEntry(int64(entry_id)) if err != nil { log.Fatal(err) } var notes = App.Db.GetDiaryEntryNotes(entry.Id) PrintEntry(entry) fmt.Println() PrintNotes(notes, App.Cfg.UseMarkdownInOutput) }, } func init() { rootCmd.AddCommand(showCmd) }