You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
diary/cmd/show.go

53 lines
1.0 KiB

/*
Copyright © 2021 NAME HERE <EMAIL ADDRESS>
*/
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
}
3 years ago
_, 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])
3 years ago
var entry, err = App.Db.GetDiaryEntry(int64(entry_id))
if err != nil {
log.Fatal(err)
}
3 years ago
var notes = App.Db.GetDiaryEntryNotes(entry.Id)
PrintEntry(entry)
fmt.Println()
PrintNotes(notes, App.Cfg.UseMarkdownInOutput)
},
}
func init() {
rootCmd.AddCommand(showCmd)
}