~dvshkn/planfile

34457ff3cd2b94d8b4d2b1b4ae72208eb4609a5a — David Knight 8 months ago 34ce411 master
add new "latest" command
2 files changed, 73 insertions(+), 4 deletions(-)

M README.md
M main.go
M README.md => README.md +22 -4
@@ 3,6 3,12 @@ planfile

Planfile is a small command-line program written in Go to manage my daily plaintext todo files. It's inspired by the now infamous John Carmack .plan file, but I've made some tweaks.

### Build

This is a stock Go project. Nothing special here.

`$ go build`

### Format

Planfiles are plaintext named with the format `YYYY-MM-DD.plan`. The first character of the line determines the kind of entry, followed by a space.


@@ 27,9 33,17 @@ x Not going to do this after all
t Something to worry about tomorrow
```

### Rules and Operation
### Commands

#### Today:

```
$ planfile
( or )
$ planfile today
```

In every case running `planfile` will result in there being a planfile for today in the current directory, and there will be an attempt at opening it with a text editor.
The `today` command is the default and will result in there being a planfile for today in the current directory. There will also be an attempt at opening today's planfile with a text editor.

- If there are no prior planfiles a new empty file will be created for today.
- If there are previous days' planfiles in the current directory the most recent one will have its contents copied and migrated to today's.


@@ 41,6 55,10 @@ Migration rules from a previous day's planfile are as follows:
- Finished and abandoned tasks are removed.
- Tomorrow tasks are converted to open tasks.

### Build
#### Latest:

`$ go build`
```
$ planfile latest
```

The `latest` command will attempt to open the most recent planfile from the current directory. It will not create any new files, and it will also ignore any planfiles dated in the future.

M main.go => main.go +51 -0
@@ 3,10 3,35 @@ package main
import (
	"fmt"
	"git.sr.ht/~dvshkn/planfile/utils"
	"os"
	"time"
)

func main() {
	if len(os.Args) == 1 {
		// "today" is the default
		today()
	} else {
		// TODO: do more formal command/flag parsing
		switch os.Args[1] {
		case "today":
			today()
		case "latest":
			latest()
		case "help":
			help()
		default:
			// for now this covers the expected "-h" and "--help"
			help()
		}
	}
}

//
// This opens today's planfile. If necessary, it will migrate up a previous
// planfile or create a new one from scratch.
//
func today() {
	// planfile name for today that may or may not exist
	todayPlanfileName := utils.GetPlanfileName(time.Now())



@@ 36,4 61,30 @@ func main() {
	if editorErr != nil {
		fmt.Println("[!]", editorErr)
	}
}

//
// This opens the most recent planfile. It will not create a new planfile.
//
func latest() {
	latestPlanfileName := utils.FindLatestPlanfile()

	if len(latestPlanfileName) > 0 {
		// a planfile exists, open it in the editor
		fmt.Println("found planfile", latestPlanfileName)
		editorErr := utils.RunEditor(latestPlanfileName)
		if editorErr != nil {
			fmt.Println("[!]", editorErr)
		}
	} else {
		// no suitable planfile
		fmt.Println("no recent planfiles in current directory")
	}
}

func help() {
	fmt.Println("\nUsage: planfile COMMAND")
	fmt.Println("\nCommands:")
	fmt.Println("  latest        Open the most recent planfile if it exists")
	fmt.Println("  today         Open or create today's planfile")
}
\ No newline at end of file