-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
67 lines (58 loc) · 1.37 KB
/
app.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
package main
import (
"fmt"
"path/filepath"
homedir "github.com/mitchellh/go-homedir"
"github.com/thinkofher/gotask/db"
"github.com/urfave/cli"
)
// Path where database will be stored
var taskdbPath = ".tasks.db"
// Returns pointer to main cli application
func prepareApp() *cli.App {
var app = cli.NewApp()
app.Before = func(c *cli.Context) error {
// Acquire the home directory
// independently of OS
home, err := homedir.Dir()
if err != nil {
return err
}
// Initalize the database if not exist
dbPath := filepath.Join(home, taskdbPath)
err = db.InitDB(dbPath)
if err != nil {
return err
}
return nil
}
app.Action = func(c *cli.Context) error {
// App prompt information about possile usage
// when user gives undefined flags or commands
if len(c.Args()) > 0 {
fmt.Println(
"Type \"gotask\", \"gotask --help\"" +
" or \"gotask help\" to get info about possible usage.")
} else {
// When typing just name of the app
// show help
err := cli.ShowAppHelp(c)
if err != nil {
return err
}
}
return nil
}
// App information
app.Name = "gotask"
app.Usage = "Add, remove and edit tasks in your local database."
app.Author = "Beniamin Dudek"
app.Email = "beniamin.dudek@yahoo.com"
app.Version = "0.0.1"
app.Commands = []cli.Command{
add, // ./add.go
show, // ./show.go
done, // ./done.go
}
return app
}