-
Notifications
You must be signed in to change notification settings - Fork 0
/
gotopus.go
44 lines (38 loc) · 898 Bytes
/
gotopus.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
package main
import (
"flag"
"fmt"
"os"
)
func Start(programName string, args ...string) int {
flagSet := flag.NewFlagSet(programName, flag.ExitOnError)
flagSet.Usage = func() {
fmt.Fprintf(flagSet.Output(), "Usage: %s <url or filepath> ...\n\n", programName)
flagSet.PrintDefaults()
}
var maxWorkers uint64
flagSet.Uint64Var(&maxWorkers, "max_workers", 0, "limits the number of workers that can run concurrently (default 0 or limitless)")
flagSet.Parse(args)
args = flagSet.Args()
if len(args) == 0 {
flagSet.Usage()
return 2
}
configs := make([]Config, len(args))
for i, configPath := range args {
cfg, err := NewConfig(configPath)
if err != nil {
fmt.Println(err)
return 2
}
configs[i] = cfg
}
for _, config := range configs {
err := Run(config, os.Stdout, os.Stderr, maxWorkers)
if err != nil {
fmt.Println(err)
return 2
}
}
return 0
}