-
Notifications
You must be signed in to change notification settings - Fork 5
/
homehub-cli.go
108 lines (95 loc) · 2.79 KB
/
homehub-cli.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package main
import (
"fmt"
"os"
"github.com/chzyer/readline"
"github.com/jamesnetherton/homehub-cli/cli"
"github.com/jamesnetherton/homehub-cli/cmd"
"github.com/jamesnetherton/homehub-cli/util"
)
func main() {
commands := initCommands()
if len(os.Args[1:]) == 0 {
readLine, err := readline.NewEx(&readline.Config{
Prompt: initPrompt(),
InterruptPrompt: "^C",
EOFPrompt: "exit",
})
if err != nil {
panic(err)
}
cli := cli.NewCLI(commands, readLine)
cli.Run()
} else {
commandLine := cmd.NewCommandLineParser(commands, os.Args[1:])
success, err := commandLine.Parse()
if !success {
if err != nil {
fmt.Printf("%s\n\n", err.Error())
}
commandLine.PrintUsage()
os.Exit(1)
}
}
}
func initPrompt() string {
var user string
if !util.StringIsEmpty(os.Getenv("USER")) {
user = os.Getenv("USER")
} else if !util.StringIsEmpty(os.Getenv("USERNAME")) {
user = os.Getenv("USERNAME")
} else {
user = "unknown"
}
return fmt.Sprintf("%s@homehub: ", user)
}
func initCommands() []cmd.Command {
var commands []cmd.Command
login := cmd.NewLoginCommand()
commands = append(commands,
login,
cmd.NewAboutCommand(),
cmd.NewBandwidthMonitorCommand(login),
cmd.NewBroadbandProductTypeCommand(login),
cmd.NewConnectedDevicesCommand(login),
cmd.NewDataPumpVersionCommand(login),
cmd.NewDataReceivedCommand(login),
cmd.NewDataSentCommand(login),
cmd.NewDeviceInfoCommand(login),
cmd.NewDhcpAuthoritativeCommand(login),
cmd.NewDhcpPoolEndCommand(login),
cmd.NewDhcpPoolStartCommand(login),
cmd.NewDhcpSubnetMaskCommand(login),
cmd.NewDownstreamSyncSpeedCommand(login),
cmd.NewEnableDebugCommand(),
cmd.NewEnableDhcpAuthoritativeCommand(login),
cmd.NewEventLogCommand(login),
cmd.NewHardwareVersionCommand(login),
cmd.NewInternetConnectionStatusCommand(login),
cmd.NewLightBrightnessCommand(login),
cmd.NewLightBrightnessSetCommand(login),
cmd.NewLightEnableCommand(login),
cmd.NewLightStatusCommand(login),
cmd.NewLocalTimeCommand(login),
cmd.NewMaintenanceFirmwareVersionCommand(login),
cmd.NewNatRulesCommand(login),
cmd.NewNatRuleCommand(login),
cmd.NewNatRuleCreateCommand(login),
cmd.NewNatRuleDeleteCommand(login),
cmd.NewPublicIPAddressCommand(login),
cmd.NewPublicSubnetMaskCommand(login),
cmd.NewRebootCommand(login),
cmd.NewSambaHostCommand(login),
cmd.NewSambaIPCommand(login),
cmd.NewSerialNumberCommand(login),
cmd.NewSoftwareVersionCommand(login),
cmd.NewUpstreamSyncSpeedCommand(login),
cmd.NewVersionCommand(login),
cmd.NewWiFiFrquency24GhzCommand(login),
cmd.NewWiFiFrequency24GhzChannelSetCommand(login),
cmd.NewWiFiFrquency5GhzCommand(login),
cmd.NewWiFiFrequency5GhzChannelSetCommand(login),
cmd.NewWiFiSSIDCommand(login),
cmd.NewWiFiSecurityModeCommand(login))
return commands
}