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
1.1 KiB
53 lines
1.1 KiB
3 years ago
|
/*
|
||
|
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",
|
||
|
Short: "A brief description of your command",
|
||
|
Long: `A longer description that spans multiple lines and likely contains examples
|
||
|
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.`,
|
||
|
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)
|
||
|
}
|