-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
41 lines (34 loc) · 1.13 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
package main
import (
"flag"
"fmt"
"github.com/hackernews-go-cli/client"
)
var (
storyNum int
askNum int
jobNum int
showNum int
)
func main() {
// maybe it can be done with sub-commands
flag.IntVar(&storyNum, "top", 0, "display top stories, you can pass arguments until 500")
flag.IntVar(&askNum, "ask", 0, "display ask stories, you can pass arguments until 200")
flag.IntVar(&jobNum, "job", 0, "display job stories, you can pass arguments until 200")
flag.IntVar(&showNum, "show", 0, "display job stories, you can pass arguments until 200")
flag.Parse()
if storyNum > 0 && storyNum <= 500 {
client.FetchStories(storyNum, "topstories")
}
if askNum > 0 && askNum <= 200 {
client.FetchStories(askNum, "askstories")
}
if jobNum > 0 && jobNum <= 200 {
client.FetchStories(jobNum, "jobstories")
}
if showNum > 0 && showNum <= 200 {
client.FetchStories(showNum, "showstories")
} else if (storyNum <= 0 || storyNum > 500) || (askNum <= 0 || askNum > 200) || (jobNum <= 0 || jobNum > 200) || (showNum <= 0 || showNum > 200) {
fmt.Println("No argument found or you exceed the max number! use --help to learn more")
}
}