Compare commits

..

2 Commits
v0.0.2 ... main

Author SHA1 Message Date
isthisnagee e4886dda7c Add config for enabling/disabling markdown output
2 years ago
nagee aeba4fa53a go mod update
2 years ago

@ -31,7 +31,7 @@ var deleteCmd = &cobra.Command{
} }
fmt.Println("Are you sure you want to delete the following entry? (y/n)") fmt.Println("Are you sure you want to delete the following entry? (y/n)")
PrintEntry(entry) PrintEntry(entry)
PrintNotes(notes) PrintNotes(notes, App.Cfg.UseMarkdownInOutput)
var response string var response string
fmt.Scanln(&response) fmt.Scanln(&response)
if response == "y" { if response == "y" {

@ -36,7 +36,7 @@ func Execute() {
func init() { func init() {
cobra.OnInitialize(InitApp) cobra.OnInitialize(InitApp)
rootCmd.PersistentFlags().String("config", "", "config file (default is $HOME/.diary.toml)") rootCmd.PersistentFlags().String("config", "", "config file (default is $HOME/config/diary/diary.toml)")
viper.BindPFlag("config", rootCmd.Flags().Lookup("config")) viper.BindPFlag("config", rootCmd.Flags().Lookup("config"))
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
} }

@ -42,7 +42,7 @@ var showCmd = &cobra.Command{
var notes = App.Db.GetDiaryEntryNotes(entry.Id) var notes = App.Db.GetDiaryEntryNotes(entry.Id)
PrintEntry(entry) PrintEntry(entry)
fmt.Println() fmt.Println()
PrintNotes(notes) PrintNotes(notes, App.Cfg.UseMarkdownInOutput)
}, },
} }

@ -16,7 +16,8 @@ import (
) )
type Cfg struct { type Cfg struct {
DbPath string DbPath string
UseMarkdownInOutput bool
} }
type TApp struct { type TApp struct {
@ -49,6 +50,10 @@ func initConfig() Cfg {
viper.SetDefault("db_path", db_path) viper.SetDefault("db_path", db_path)
} }
if viper.Get("use_markdown_output") == nil {
viper.SetDefault("use_markdown_output", true)
}
viper.AutomaticEnv() // read in environment variables that match viper.AutomaticEnv() // read in environment variables that match
if err := viper.ReadInConfig(); err != nil { if err := viper.ReadInConfig(); err != nil {
@ -59,7 +64,7 @@ func initConfig() Cfg {
} }
} }
return Cfg{viper.GetString("db_path")} return Cfg{viper.GetString("db_path"), viper.GetBool("use_markdown_output")}
} }
func InitApp() { func InitApp() {
@ -100,21 +105,26 @@ func PrintEntries(entries []*model.DiaryEntry) {
} }
} }
func PrintNote(note *model.DiaryEntryNote, add_tail bool) { func PrintNote(note *model.DiaryEntryNote, add_tail bool, use_markdown bool) {
created_time := time.Unix(note.CreatedAt, 0).Format(time_fmt_str) created_time := time.Unix(note.CreatedAt, 0).Format(time_fmt_str)
fmt.Println("---note ( id:", note.Id, ")", created_time) fmt.Println("---note ( id:", note.Id, ")", created_time)
fmt.Println() fmt.Println()
body := markdown.Render(note.Body, 80, 3) var body string
fmt.Println(string(body)) if use_markdown {
body = string(markdown.Render(note.Body, 80, 3))
} else {
body = note.Body
}
fmt.Println(body)
if add_tail { if add_tail {
fmt.Println("---") fmt.Println("---")
} }
} }
func PrintNotes(notes []*model.DiaryEntryNote) { func PrintNotes(notes []*model.DiaryEntryNote, use_markdown bool) {
for idx, entry := range notes { for idx, entry := range notes {
var is_last = idx == len(notes)-1 var is_last = idx == len(notes)-1
PrintNote(entry, is_last) PrintNote(entry, is_last, use_markdown)
} }
} }

@ -1,6 +1,5 @@
/* /*
Copyright © 2021 NAME HERE <EMAIL ADDRESS> Copyright © 2021 NAME HERE <EMAIL ADDRESS>
*/ */
package main package main

Loading…
Cancel
Save