-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflag.go
53 lines (42 loc) · 1013 Bytes
/
flag.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
package main
import (
"flag"
"log"
"os"
"strconv"
"astuart.co/limio"
)
var (
serveAPI = flag.Bool("serve", false, "serve the api")
searchType = flag.String("t", "movie", "the type of search to perform")
rateLimit = flag.String("r", "", "the rate limit")
nc = flag.Bool("nocache", false, "skip cache")
clr = flag.Bool("clear", false, "clear cache")
num = flag.Int("n", 100, "number to download")
nzbLink = flag.String("l", "", "url to an nzb")
)
var downRate int
func init() {
flag.Parse()
if *searchType == "tv" {
*searchType = "tvsearch"
}
if *rateLimit == "" {
*rateLimit = os.Getenv("SAB_RATE")
}
if len(*rateLimit) > 0 {
rl := []byte(*rateLimit)
unit := rl[len(rl)-1]
rl = rl[:len(rl)-1]
qty, err := strconv.ParseFloat(string(rl), 64)
if err != nil {
log.Printf("Bad quantity: %s\n", *rateLimit)
}
switch unit {
case 'm':
downRate = int(qty * float64(limio.MB))
case 'k':
downRate = int(qty * float64(limio.KB))
}
}
}