Compare commits

..

No commits in common. 'main' and 'v0.0.2' have entirely different histories.
main ... v0.0.2

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

@ -36,7 +36,7 @@ func Execute() {
func init() {
cobra.OnInitialize(InitApp)
rootCmd.PersistentFlags().String("config", "", "config file (default is $HOME/config/diary/diary.toml)")
rootCmd.PersistentFlags().String("config", "", "config file (default is $HOME/.diary.toml)")
viper.BindPFlag("config", rootCmd.Flags().Lookup("config"))
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)
PrintEntry(entry)
fmt.Println()
PrintNotes(notes, App.Cfg.UseMarkdownInOutput)
PrintNotes(notes)
},
}

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

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

Loading…
Cancel
Save