-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmasterstat.go
61 lines (48 loc) · 1.11 KB
/
masterstat.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
60
61
package main
import (
"errors"
"fmt"
"log"
"os"
"github.com/urfave/cli/v2"
"github.com/vikpe/masterstat"
)
func run(args []string) int {
cli.AppHelpTemplate = `{{.Name}} [{{.Version}}]
{{.Description}}
Usage: {{.UsageText}}
Example: {{.Name}} master.quakeworld.nu:27000 qwmaster.ocrana.de:27000
`
app := &cli.App{
Name: "masterstat",
Description: "Fetch server addresses from QuakeWorld master servers.",
UsageText: "masterstat [<address> ...]",
Version: "__VERSION__", // updated during build workflow
Action: func(c *cli.Context) error {
masterAddresses := c.Args().Slice()
serverAddresses, errs := masterstat.GetServerAddressesFromMany(masterAddresses)
for _, serverAddress := range serverAddresses {
fmt.Println(serverAddress)
}
if len(errs) > 0 {
log.Printf("ERRORS (%d):", len(errs))
for _, err := range errs {
log.Print(err)
}
return errors.New("error")
}
return nil
},
}
if 1 == len(args) {
args = append(args, "--help")
}
err := app.Run(args)
if err != nil {
return 1
}
return 0
}
func main() {
os.Exit(run(os.Args))
}