-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcommands.go
83 lines (75 loc) · 1.54 KB
/
commands.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
package main
import (
"fmt"
"os"
"github.com/codegangsta/cli"
"github.com/kakakakakku/togoo/command"
)
// GlobalFlags is global option for all command.
var GlobalFlags = []cli.Flag{}
var forceFlags = []cli.Flag{
cli.BoolFlag{
Name: "force, f",
Usage: "Force initialize even if database already existed.",
},
}
var allListFlags = []cli.Flag{
cli.BoolFlag{
Name: "all, a",
Usage: "List all tasks.",
},
}
var allDeleteFlags = []cli.Flag{
cli.BoolFlag{
Name: "all, a",
Usage: "Delete all tasks.",
},
}
// Commands are slice of command.
var Commands = []cli.Command{
{
Name: "init",
Usage: "Initialize SQLite database",
Action: command.CmdInit,
Flags: forceFlags,
},
{
Name: "add",
Aliases: []string{"a"},
Usage: "Add task",
Action: command.CmdAdd,
Flags: []cli.Flag{},
},
{
Name: "update",
Aliases: []string{"u"},
Usage: "Update task",
Action: command.CmdUpdate,
Flags: []cli.Flag{},
},
{
Name: "list",
Aliases: []string{"l"},
Usage: "Show all tasks",
Action: command.CmdList,
Flags: allListFlags,
},
{
Name: "done",
Aliases: []string{"d"},
Usage: "Mark a task as done",
Action: command.CmdDone,
Flags: []cli.Flag{},
},
{
Name: "delete",
Usage: "Delete task",
Action: command.CmdDelete,
Flags: allDeleteFlags,
},
}
// CommandNotFound is custom error.
func CommandNotFound(c *cli.Context, command string) {
fmt.Fprintf(os.Stderr, "%s: '%s' is not a %s command. See '%s --help'.", c.App.Name, command, c.App.Name, c.App.Name)
os.Exit(2)
}