-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
118 lines (110 loc) · 2.43 KB
/
main.go
File metadata and controls
118 lines (110 loc) · 2.43 KB
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
package main
import (
"fmt"
"github.com/dutchakdev/clif/category"
"github.com/dutchakdev/clif/command"
"github.com/dutchakdev/clif/db"
"github.com/dutchakdev/clif/globals"
"github.com/dutchakdev/clif/helpers"
"github.com/dutchakdev/clif/version"
"gopkg.in/urfave/cli.v1"
"os"
"strings"
)
func main() {
app := cli.NewApp()
app.Name = "clif"
app.Usage = "CLI Favorites"
app.Version = version.Version
app.EnableBashCompletion = true
app.Flags = globals.CommonFlags
app.Action = func(c *cli.Context) error {
if (len(os.Args) >= 2) {
command.RunCmdByPath(os.Args[1], os.Args[2:])
} else {
command.FindCmdInCategories("")
}
return nil
}
app.Commands = []cli.Command{
{
Name: "categories",
Aliases: []string{"c"},
Usage: "Categories of commands",
Subcommands: []cli.Command{
{
Name: "add",
Usage: "add a new category",
Action: func(c *cli.Context) error {
category.CreateCategory()
return nil
},
Flags: []cli.Flag {
cli.StringFlag{
Name: "category, c",
Value: "",
Usage: "Category name",
Destination: &globals.CategoryName,
},
cli.StringFlag{
Name: "interactive, i",
Value: "false",
Usage: "Ask confirmation for certain operations",
Destination: &globals.Interactive,
},
},
},
{
Name: "rm",
Usage: "remove category",
Action: func(c *cli.Context) error {
category.RemoveCategory(strings.Join(os.Args[3:], " "))
return nil
},
Flags: globals.CommonFlags,
},
{
Name: "ls",
Usage: "list category",
Action: func(c *cli.Context) error {
fmt.Println(strings.Join(category.GetCategories()[1:], "\n"))
return nil
},
},
},
},
{
Name: "command",
Aliases: []string{"cmd"},
Usage: "Commands",
Subcommands: []cli.Command{
{
Name: "add",
Usage: "add a new command",
Action: command.ActionAddCmd,
},
{
Name: "rm",
Usage: "remove command",
Action: func(c *cli.Context) error {
fmt.Println("new task template: ", c.Args().First())
return nil
},
},
//{
// Name: "ls",
// Usage: "list command",
// Action: func(c *cli.Context) error {
// fmt.Println("new task template: ", c.Args().First())
// return nil
// },
//},
},
},
}
err := app.Run(os.Args)
helpers.CheckErr(err)
}
func init() {
db.PrepareDatabase()
}