-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
51 lines (43 loc) · 1.24 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
package main
import (
"flag"
"fmt"
"os"
)
func main() {
var (
directory string
format string
category string
searchwork string
)
f := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
f.StringVar(&directory, "d", "", "specify a directory to save the file")
f.StringVar(&format, "f", "pdf", "specify the ebook format")
f.StringVar(&category, "c", "all", "specify the ebook category")
f.StringVar(&searchwork, "s", "", "specify the search word for ebook")
f.Parse(os.Args[1:])
for 0 < f.NArg() {
f.Parse(f.Args()[1:])
}
if directory == "" {
fmt.Println("-d (save directory is required)")
usage := `
$ oreillyfreebook -d directory [-f format] [-c category]
-d directory Specify the directory to save
-f format Specify the ebook format to download; the default is "pdf"
"pdf", "mobi", "epub"
-c category Specify the ebook category to download;
if not specified, all categories will be download
"business", "design", "iot", "data", "programming", "security", "web-platform", "webops"
-s search-word Specify the search word for ebook`
fmt.Println(usage)
os.Exit(1)
}
if err := os.MkdirAll(directory, 0777); err != nil {
fmt.Println(err)
os.Exit(1)
}
d := Downloader{}
d.Download(category, format, directory, searchwork)
}