-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
162 lines (149 loc) · 3.49 KB
/
main.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package main
import (
"fmt"
"os"
"os/user"
"path/filepath"
"strings"
"github.com/ruggi/carmack/commands"
"github.com/ruggi/carmack/context"
"github.com/ruggi/carmack/plan"
"github.com/ruggi/carmack/shell"
"github.com/ruggi/carmack/util"
"github.com/urfave/cli"
)
const (
folderName = ".carmack"
)
func main() {
ctx, err := loadContext(folderName)
if err != nil {
panic(err)
}
err = os.MkdirAll(ctx.UserFolder(), 0755)
if err != nil {
panic(err)
}
app := cli.NewApp()
app.Name = "carmack"
app.Usage = "track daily progress with .plan files"
app.Version = util.Version
app.Description = `
carmack is a daily progress tracker for teams, inspired by John Carmack's .plan files and based on git.
Daily notes and tasks are stored in plain .plan files, using a simple and grep-able format,
divided into done, completed, canceled, and open entries.
See https://github.com/ruggi/carmack#usage for more.
`
app.Commands = []cli.Command{
{
Name: "add",
Usage: "Add a new entry to today's plan",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "done,d",
Usage: "[*] for something you started and completed today",
},
cli.BoolFlag{
Name: "completed,c",
Usage: "[+] for something old that you completed today",
},
cli.BoolFlag{
Name: "canceled,x",
Usage: "[-] for something old that has been canceled/decided against",
},
},
Action: func(c *cli.Context) error {
entry := strings.Join(c.Args(), " ")
entryType := makeEntryTypeFromFlags(c)
return commands.Add(ctx, entry, entryType)
},
},
{
Name: "show",
Usage: "Show open entries",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "open,o",
Usage: "show open entries",
},
cli.BoolFlag{
Name: "done,d",
Usage: "show done entries",
},
cli.BoolFlag{
Name: "completed,c",
Usage: "show completed entries",
},
cli.BoolFlag{
Name: "canceled,x",
Usage: "show canceled entries",
},
cli.StringFlag{
Name: "user,u",
Usage: "show entries for a specific user",
},
},
Action: func(c *cli.Context) error {
if !(c.Bool("done") || c.Bool("completed") || c.Bool("canceled") || c.Bool("open")) {
return fmt.Errorf("missing entry type flag")
}
user := c.String("user")
entryType := makeEntryTypeFromFlags(c)
return commands.Show(ctx, user, entryType)
},
},
{
Name: "list",
Aliases: []string{"ls"},
Usage: "List all plan files",
Action: func(c *cli.Context) error {
return commands.List(ctx)
},
},
{
Name: "git",
Usage: "Issue git commands",
Subcommands: []cli.Command{
{
Name: "init",
Usage: "initialize plan files git repo",
Action: func(c *cli.Context) error {
return commands.GitInit(ctx)
},
},
},
SkipFlagParsing: true,
Action: func(c *cli.Context) error {
return commands.Git(ctx, c.Args()...)
},
},
}
app.RunAndExitOnError()
}
func loadContext(folderName string) (*context.Context, error) {
u, err := user.Current()
if err != nil {
return nil, err
}
folder := filepath.Join(u.HomeDir, folderName)
username := shell.Git.UserName(folder)
if username == "" {
username = u.Username
}
return &context.Context{
Username: username,
Folder: folder,
}, nil
}
func makeEntryTypeFromFlags(c *cli.Context) plan.EntryType {
if c.Bool("done") {
return plan.Done
}
if c.Bool("completed") {
return plan.Completed
}
if c.Bool("canceled") {
return plan.Canceled
}
return plan.Note
}