-
Notifications
You must be signed in to change notification settings - Fork 0
/
arguments.go
59 lines (48 loc) · 1.43 KB
/
arguments.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
package main
import (
"fmt"
"os"
"github.com/akamensky/argparse"
)
func parseArgs(args []string) {
// Create new parser object
parser := argparse.NewParser("PexelsArchiver", "Archiving tool for pexels.com")
// Create flags
output := parser.String("o", "output", &argparse.Options{
Required: false,
Default: "./Downloads",
Help: "Output directory"})
randomUA := parser.Flag("", "random-ua", &argparse.Options{
Required: false,
Help: "Randomize user agent on request"})
concurrency := parser.Int("j", "concurrency", &argparse.Options{
Required: false,
Default: 2,
Help: "Concurrent jobs for download"})
startID := parser.Int("", "start-id", &argparse.Options{
Required: false,
Default: 1,
Help: "Start from this ID"})
stopID := parser.Int("", "stop-id", &argparse.Options{
Required: false,
Default: 1000000000,
Help: "Stop at this ID"})
verbose := parser.Flag("v", "verbose", &argparse.Options{
Required: false,
Help: "Display various informations"})
// Parse input
err := parser.Parse(args)
if err != nil {
// In case of error print error and print usage
// This can also be done by passing -h or --help flags
fmt.Print(parser.Usage(err))
os.Exit(0)
}
// Fill arguments structure
arguments.Output = *output
arguments.Concurrency = *concurrency
arguments.RandomUA = *randomUA
arguments.Verbose = *verbose
arguments.StartID = *startID
arguments.StopID = *stopID
}