-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
121 lines (107 loc) · 2.44 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
package main
import (
"fmt"
"os"
"os/user"
"path/filepath"
"github.com/spf13/viper"
"github.com/urfave/cli"
"github.com/gumieri/note/cmd"
)
func main() {
currentUser, err := user.Current()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
viper.SetDefault("editor", "vim")
viper.SetDefault("notePath", filepath.Join(currentUser.HomeDir, "Notes"))
viper.SetConfigName(".noteconfig")
viper.AddConfigPath(currentUser.HomeDir)
viper.AddConfigPath(".")
viper.AutomaticEnv()
_ = viper.ReadInConfig()
app := cli.NewApp()
app.Name = "Note"
app.Version = "1.1.0"
app.Usage = "Quick and easy Command-line tool for taking notes"
app.UsageText = "note [just type a text] [or command] [with command options]"
app.ArgsUsage = "[text]"
app.Action = cmd.WriteNote
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "title, t",
Usage: "Inform a title for the note",
},
}
app.Commands = []cli.Command{
{
Name: "show",
Usage: "Show a note content",
Action: cmd.ShowNote,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "no-title",
Usage: "Don't print note's title",
},
cli.BoolFlag{
Name: "case-sensitive, s",
Usage: "Must match the case of the informed parameters and note's title",
},
},
},
{
Name: "edit",
Aliases: []string{"e"},
Usage: "Edit a note content",
Action: cmd.EditNote,
Flags: []cli.Flag{
cli.StringFlag{
Name: "title, t",
Usage: "Edit the title of the note",
},
cli.BoolFlag{
Name: "case-sensitive, s",
Usage: "Must match the case of the informed parameters and note's title",
},
},
},
{
Name: "delete",
Aliases: []string{"del", "d", "rm"},
Usage: "Delete a note",
Action: cmd.DeleteNote,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "yes, y",
Usage: "Delete without asking confirmation",
},
cli.BoolFlag{
Name: "case-sensitive, s",
Usage: "Must match the case of the informed parameters and note's title",
},
},
},
{
Name: "list",
Aliases: []string{"ls", "l"},
Usage: "List notes",
Action: cmd.ListNotes,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "no-header",
Usage: "Don't print the description header of the columns",
},
cli.BoolFlag{
Name: "filename",
Usage: "Print only the filenames of the notes at the notePath",
},
},
},
}
err = app.Run(os.Args)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}