~dvshkn/planfile

ref: 34ce4118513c1048ed016eed0bde9d14435c1ad5 planfile/main.go -rw-r--r-- 1.0 KiB
34ce4118David Knight first post 10 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main

import (
	"fmt"
	"git.sr.ht/~dvshkn/planfile/utils"
	"time"
)

func main() {
	// planfile name for today that may or may not exist
	todayPlanfileName := utils.GetPlanfileName(time.Now())

	// name of most recent planfile in current directory, also may not exist
	latestPlanfileName := utils.FindLatestPlanfile()

	var fileErr error	
	if len(latestPlanfileName) == 0 {
		// create new empty planfile
		fmt.Println("no planfiles in current directory, creating new empty planfile")
		fileErr = utils.CreateEmpty(todayPlanfileName)
	} else if latestPlanfileName != todayPlanfileName {
		// latest is in the past, copy to new planfile
		fmt.Println("no planfile found for today, creating planfile from", latestPlanfileName)
		fileErr = utils.CreateFrom(todayPlanfileName, latestPlanfileName)
	} else {
		// today's planfile already exists
		fmt.Println("using today's existing planfile")
	}

	if fileErr != nil {
		fmt.Println("[!]", fileErr)
	}

	editorErr := utils.RunEditor(todayPlanfileName)

	if editorErr != nil {
		fmt.Println("[!]", editorErr)
	}
}