-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
64 lines (52 loc) · 927 Bytes
/
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
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"errors"
"flag"
"fmt"
"log"
"os"
)
type Runner interface {
Init([]string) error
Run() error
PrintUsage()
Name() string
}
var cmds = []Runner{
ClientSubCommand(),
}
func help() {
fmt.Println("Egressinator")
fmt.Println("Determine unrestricted ports that can egress the network")
for _, r := range cmds {
r.PrintUsage()
}
}
func root(args []string) error {
if len(args) < 1 {
help()
return errors.New("No subcommand specified")
}
subcommand := os.Args[1]
for _, cmd := range cmds {
if cmd.Name() == subcommand {
err := cmd.Init(os.Args[2:])
if err != nil {
if err != flag.ErrHelp {
fmt.Println("Error: ", err.Error())
cmd.PrintUsage()
}
return nil
}
return cmd.Run()
}
}
help()
return fmt.Errorf("Unknown subcommand: %s", subcommand)
}
func main() {
if err := root(os.Args[1:]); err != nil {
log.Println(err)
os.Exit(1)
}
}