/
main.go
48 lines (39 loc) · 842 Bytes
/
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
package main
import (
"fmt"
"os"
"path/filepath"
"github.com/naoty/todo/cmd"
"github.com/naoty/todo/repository/filesystem"
)
// Version is the version of this application.
// Makefile injects git tag into this value.
var Version = "0.0.0"
func main() {
stdio := cmd.CLI{
Reader: os.Stdin,
Writer: os.Stdout,
ErrorWriter: os.Stderr,
}
root := rootPath()
repo, err := filesystem.New(root)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
commandFactory := cmd.Lookup(os.Args)
command := commandFactory(stdio, Version, repo)
status := command.Run(os.Args)
os.Exit(status)
}
func rootPath() string {
root := os.Getenv("TODOS_PATH")
if root == "" {
home, err := os.UserHomeDir()
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
root = filepath.Join(home, ".todos")
}
return root
}