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.
53 lines
1008 B
53 lines
1008 B
/*
|
|
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
|
|
}
|
|
_, err = App.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.GetDiaryEntry(int64(entry_id))
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
var notes = App.GetDiaryEntryNotes(entry.Id)
|
|
PrintEntry(entry)
|
|
fmt.Println()
|
|
PrintNotes(notes)
|
|
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(showCmd)
|
|
}
|