-
Notifications
You must be signed in to change notification settings - Fork 15
/
main.go
178 lines (159 loc) · 4.55 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package main
import (
"fmt"
"log"
"os"
"strconv"
"ancestorquotes/commands"
"github.com/urfave/cli"
)
func main() {
app := cli.NewApp()
app.Name = "ancestorquotes"
app.Author = "bruno-chavez"
app.Usage = "Brings quotes from the darkest of dungeons!"
app.Version = "2.0.0"
app.Commands = []cli.Command{
{
Name: "persistent",
Usage: "Makes the Ancestor say a quote every certain amount of time",
Aliases: []string{"p"},
Subcommands: []cli.Command{
{
Name: "minute",
Usage: "Intervals in minutes between every quote",
Aliases: []string{"m", "minutes"},
Action: func(c *cli.Context) error {
//os.Args[3] is the interval of time between quotes.
if len(os.Args) < 4 {
fmt.Println("Incorrect use of the persistent commnad," +
" type 'ancestorquotes persistent help' for more information")
return nil
}
timer, err := strconv.Atoi(os.Args[3])
if err != nil {
fmt.Println("Incorrect use of the persistent commnad," +
" type 'ancestorquotes persistent help' for more information")
return nil
}
// When using strconv on a non numeral string it gets converted 0
if timer == 0 {
fmt.Println("Incorrect use of the persistent commnad," +
" type 'ancestorquotes persistent help' for more information")
return nil
}
commands.Persistent(timer, "minute")
return nil
},
},
{
Name: "second",
Usage: "Intervals in seconds between every quote",
Aliases: []string{"s", "seconds"},
Action: func(c *cli.Context) error {
//os.Args[3] is the interval of time between quotes.
if len(os.Args) < 4 {
fmt.Println("Incorrect use of the persistent commnad," +
" type 'ancestorquotes persistent help' for more information")
return nil
}
timer, err := strconv.Atoi(os.Args[3])
if err != nil {
fmt.Println("Incorrect use of the persistent commnad," +
" type 'ancestorquotes persistent help' for more information")
return nil
}
// When using strconv on a non numeral string it gets converted 0
if timer == 0 {
fmt.Println("Incorrect use of the persistent commnad," +
" type 'ancestorquotes persistent help' for more information")
return nil
}
commands.Persistent(timer, "second")
return nil
},
},
},
},
{
Name: "all",
Usage: "Shows all quotes the Ancestor has to offer",
Aliases: []string{"a"},
Action: func(c *cli.Context) error {
commands.AllQuotes()
return nil
},
},
{
Name: "chat",
Usage: "The Ancestor talks with himself in a maddening fashion",
Aliases: []string{"c"},
Action: func(c *cli.Context) error {
commands.Chat()
return nil
},
},
{
Name: "talkback",
Usage: "You can talk to the Ancestor and the Ancestor replies back in a crazy manner",
Aliases: []string{"t"},
Action: func(c *cli.Context) error {
commands.TalkBack()
return nil
},
},
{
Name: "search",
Usage: "Searches all quotes the Ancestor has ever said with the word searched in them",
Aliases: []string{"s"},
Action: func(c *cli.Context) error {
commands.Search(c.Args().First())
return nil
},
},
{
Name: "number",
Usage: "Shows a given number of random quotes the Ancestor has to offer",
Aliases: []string{"n", "numbers"},
Action: func(c *cli.Context) error {
if len(os.Args) != 3 {
fmt.Println("Incorrect use of the number command, example of correct usage: ancestorquotes number 3")
return nil
}
number, err := strconv.Atoi(os.Args[2])
if err != nil {
fmt.Println("input parameter must be integer, example of correct usage: ancestorquotes number 3")
return nil
}
if number < 1 {
fmt.Println("input parameter must be greater than zero, example of correct usage: ancestorquotes number 3")
return nil
}
commands.NumberOfQuotes(number)
return nil
},
},
{
Name: "typed",
Usage: "Prints a random quote character-by-character, like a typewriter.",
Aliases: []string{"typed"},
Action: func(c *cli.Context) error {
commands.Typed()
return nil
},
},
}
app.Action = func(c *cli.Context) error {
if len(c.Args()) > 0 {
fmt.Printf("%v is not a valid command.\n"+
"Enter ancestorquotes --help to see the list of valid commands.\n", c.Args()[0])
} else {
fmt.Println(commands.RandomQuote())
}
return nil
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}