2018-05-07 15:58:42 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
"log"
|
|
|
|
"github.com/dballard/markdown-bullet-journal/process"
|
|
|
|
"fmt"
|
2018-05-08 18:11:58 +00:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
2018-05-07 15:58:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const template = `# Work
|
|
|
|
- [ ] read emails
|
|
|
|
|
|
|
|
# Home
|
|
|
|
- [ ] do laundry
|
|
|
|
- [ ] Weekly shopping
|
|
|
|
- [ ] apples
|
|
|
|
- [ ] bread
|
|
|
|
|
|
|
|
# Daily Workout
|
|
|
|
|
|
|
|
## Upper Body
|
|
|
|
- [ ] 0x10 pushups
|
|
|
|
|
|
|
|
## Core
|
|
|
|
- [ ] 0x10 crunches
|
|
|
|
`
|
|
|
|
|
|
|
|
type processHandler struct {
|
|
|
|
File *os.File
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ph *processHandler) Writeln(line string) {
|
|
|
|
ph.File.WriteString(line + "\n")
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOP
|
|
|
|
func (ph *processHandler) Eof() {}
|
|
|
|
func (ph *processHandler) NewFile() {}
|
|
|
|
|
2018-05-08 18:11:58 +00:00
|
|
|
func (ph *processHandler) ProcessLine(line string, indentLevel int, stack []string, todo bool, done bool, repTask process.RepTask) {
|
2018-05-07 15:58:42 +00:00
|
|
|
// TODO: handle [x] numXnum
|
2018-05-08 18:11:58 +00:00
|
|
|
if !done || repTask.Is {
|
|
|
|
if repTask.Is {
|
|
|
|
ph.Writeln(strings.Repeat("\t", indentLevel) + "- [ ] 0x" + strconv.Itoa(repTask.B) + stack[len(stack)-1] )
|
|
|
|
} else {
|
|
|
|
ph.Writeln(line)
|
|
|
|
}
|
2018-05-07 15:58:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
ph := new(processHandler)
|
|
|
|
files := process.GetFiles()
|
|
|
|
|
|
|
|
fileName := time.Now().Format("2006-01-02") + ".md"
|
|
|
|
|
|
|
|
if _, err := os.Stat(fileName); os.IsNotExist(err) {
|
|
|
|
ph.File, err = os.Create(fileName)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("Cannot open: ", fileName, " > ", err)
|
|
|
|
}
|
|
|
|
defer ph.File.Close()
|
|
|
|
} else {
|
|
|
|
log.Fatalf("File " + fileName + " already exists!")
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(files) == 0 {
|
|
|
|
// create first from template
|
|
|
|
fmt.Println("Generating " + fileName + " from template")
|
|
|
|
ph.File.WriteString(template)
|
|
|
|
} else {
|
|
|
|
lastFile := files[len(files)-1]
|
|
|
|
fmt.Println ("Migrating " + lastFile + " to " + fileName)
|
|
|
|
process.ProcessFile(ph, lastFile)
|
|
|
|
}
|
|
|
|
}
|