-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
38 lines (34 loc) · 857 Bytes
/
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
package main
import (
"flag"
"fmt"
"log"
)
func main() {
// Define & parse flags
search := flag.String("search", "", "search for quotes on a topic")
author := flag.String("author", "", "search for quotes by author")
tag := flag.String("tag", "", "search for quotes with tag")
showTags := flag.Bool("showtags", false, "display tags for each quote")
max := flag.Int("n", 10, "maximum number of results")
flag.Parse()
// Search or get QOTD depending on flags
if *search != "" || *author != "" || *tag != "" {
quotes, err := GetQuotes(*search, *author, *tag, *max)
if err != nil {
log.Fatal(err)
}
for i, quote := range quotes {
printQuote(quote, *showTags)
if i != len(quotes)-1 {
fmt.Println()
}
}
} else {
quote, err := GetRandomQuote()
if err != nil {
log.Fatal(err)
}
printQuote(quote, *showTags)
}
}