|
|
@ -16,8 +16,7 @@ import (
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type Cfg struct {
|
|
|
|
type Cfg struct {
|
|
|
|
DbPath string
|
|
|
|
DbPath string
|
|
|
|
UseMarkdownInOutput bool
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type TApp struct {
|
|
|
|
type TApp struct {
|
|
|
@ -50,10 +49,6 @@ 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 {
|
|
|
@ -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() {
|
|
|
|
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)
|
|
|
|
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()
|
|
|
|
var body string
|
|
|
|
body := markdown.Render(note.Body, 80, 3)
|
|
|
|
if use_markdown {
|
|
|
|
fmt.Println(string(body))
|
|
|
|
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, use_markdown bool) {
|
|
|
|
func PrintNotes(notes []*model.DiaryEntryNote) {
|
|
|
|
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, use_markdown)
|
|
|
|
PrintNote(entry, is_last)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|