This repository has been archived by the owner on Dec 8, 2019. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.go
74 lines (61 loc) · 2.25 KB
/
config.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
package main
import (
"github.com/jessevdk/go-flags"
)
type raspberryConfig struct {
TouchPin string `long:"touchpin" description:"BCM number of the touch input pin."`
MotorPin string `long:"motorpin" description:"BCM number of the motor output pin."`
BuzzerPin string `long:"buzzerpin" description:"BCM number of the buzzer output pin."`
}
type mockConfig struct {
Listen string `long:"listen" description:"Add an interface/port to listen for mock touches."`
}
type torConfig struct {
Path string `long:"path" description:"The path to the Tor binary."`
}
type profilingConfig struct {
Listen string `long:"listen" description:"Add an interface/port to listen for profiling data."`
}
type networkConfig struct {
Interface string `long:"ifname" description:"Wifi interface name."`
}
type pairingConfig struct {
Interface string `long:"ifname" description:"Bluetooth interface name."`
}
type config struct {
ShowVersion bool `short:"v" long:"version" description:"Display version information and exit."`
Debug bool `long:"debug" description:"Start in debug mode."`
Machine string `long:"machine" description:"The machine controller to use." choice:"raspberry" choice:"mock"`
Raspberry *raspberryConfig `group:"Raspberry" namespace:"raspberry"`
Mock *mockConfig `group:"Mock" namespace:"mock"`
Net *networkConfig `group:"Network" namespace:"network"`
Pairing *pairingConfig `group:"Pairing" namespace:"pairing"`
DataDir string `long:"datadir" description:"The directory to store sweetd's data within.'"`
Updater string `long:"updater" description:"The updater to use." choice:"none" choice:"mender"`
Tor *torConfig `group:"Tor" namespace:"tor"`
Profiling *profilingConfig `group:"Profiling" namespace:"profiling"`
}
func loadConfig() (*config, error) {
defaultCfg := config{
Machine: "raspberry",
Debug: false,
Raspberry: &raspberryConfig{
TouchPin: "25",
MotorPin: "23",
BuzzerPin: "24",
},
Net: nil,
Pairing: nil,
DataDir: "./data",
Updater: "none",
Tor: &torConfig{
Path: "",
},
}
preCfg := defaultCfg
if _, err := flags.Parse(&preCfg); err != nil {
return nil, err
}
cfg := preCfg
return &cfg, nil
}