-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (48 loc) · 1.64 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
52
53
54
55
56
57
58
59
60
package main
import (
"fmt"
"os"
"reflect"
"github.com/grimdork/opt"
)
var o struct {
opt.DefaultHelp
Serve CmdServe `command:"serve" help:"Start the server."`
Init CmdInit `command:"init" help:"Initialize the configuration."`
ListCanary CmdListCanaries `command:"listcanaries" help:"List all passive clients." aliases:"lsc" group:"Canaries"`
SetCanary CmdSetCanary `command:"setcanary" help:"Set a passive client." aliases:"sc" group:"Canaries"`
DeleteCanary CmdDeleteCanary `command:"deletecanary" help:"Delete a passive client." aliases:"dc" group:"Canaries"`
ListScouts CmdListScouts `command:"listscouts" help:"List all scouts (active watcher)." aliases:"lss" group:"Scouts"`
SetScout CmdSetScout `command:"setscout" help:"Creates or modifies a scout." aliases:"ss" group:"Scouts"`
DeleteScout CmdDeleteScout `command:"deletescout" help:"Deletes a scout." aliases:"ds" group:"Scouts"`
ListKey CmdListKeys `command:"listkeys" help:"List all keys." aliases:"lsk" group:"Keys"`
SetKey CmdSetKey `command:"setkey" help:"Set a key." aliases:"sk" group:"Keys"`
DeleteKey CmdDeleteKey `command:"deletekey" help:"Delete a key." aliases:"dk" group:"Keys"`
}
func main() {
err := opt.HandleCommands(&o)
if err != nil {
if err == opt.ErrNoCommand {
fmt.Printf("Unknown command or no command specified.\n}")
os.Exit(1)
}
panic(err)
}
}
func parse(x any) error {
a := opt.Parse(x)
v := reflect.ValueOf(x).Elem().FieldByName("Help")
if v.Bool() {
a.Usage()
return nil
}
err := a.RunCommand(false)
if err != nil {
if err == opt.ErrNoCommand {
a.Usage()
return nil
}
return err
}
return nil
}