-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.go
56 lines (49 loc) · 1.73 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
package main
import (
"fmt"
"github.com/alecthomas/kong"
"os"
)
type GlobalOptions struct {
Verbose bool
Quiet bool
OutputFormat OutputFormat
TokenDir string
model NetgearModel
token string
}
var cli struct {
HelpAll HelpAllFlag `help:"advanced/full help"`
Verbose bool `help:"verbose log messages" short:"v"`
Quiet bool `help:"no log messages" short:"q"`
OutputFormat OutputFormat `help:"what output format to use [md, json]" enum:"md,json" default:"md" short:"f"`
TokenDir string `help:"directory to store login tokens" default:"" short:"d"`
Version VersionCommand `cmd:"" name:"version" help:"show version"`
Login LoginCommand `cmd:"" name:"login" help:"create a session for further commands (requires admin console password)"`
Poe PoeCommand `cmd:"" name:"poe" help:"show POE status or change the configuration"`
Port PortCommand `cmd:"" name:"port" help:"show port status or change the configuration for a port"`
ShowDebug DebugReportCommand `cmd:"" name:"debug-report" help:"show information from the switch communication, useful for supporting development and bug fixes"`
}
func main() {
// If running without any extra arguments, default to the --help flag
if len(os.Args) < 2 {
os.Args = append(os.Args, "--help")
}
options := kong.Parse(&cli,
kong.UsageOnError(),
kong.ConfigureHelp(kong.HelpOptions{
Compact: true,
NoExpandSubcommands: true,
}),
)
err := options.Run(&GlobalOptions{
Verbose: cli.Verbose,
Quiet: cli.Quiet,
OutputFormat: cli.OutputFormat,
TokenDir: cli.TokenDir,
})
if err != nil {
fmt.Printf("Error: %s\n", err.Error())
os.Exit(1)
}
}