-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
53 lines (43 loc) · 1.23 KB
/
main.go
File metadata and controls
53 lines (43 loc) · 1.23 KB
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
package main
import (
"flag"
"fmt"
"os"
"github.com/srl-labs/frontpanel-cli-plugin/frontpanel"
)
var (
version = "0.0.0"
commit = ""
)
func main() {
versionFlag := flag.Bool("version", false, "print the version and exit")
imageFlag := flag.String("image", "", "print the front panel image and exit")
imageProtocolFlag := flag.String("image-protocol", "auto", "image protocol: auto|kitty|iterm")
portLabelsFlag := flag.Bool("port-labels", false, "overlay port labels (1/1, 1/2, ...)")
portStatesJSONFlag := flag.String("port-states-json", "",
"JSON object of interface state by name, e.g. {\"ethernet-1/1\":\"up\"}")
flag.Parse()
if *versionFlag {
fmt.Println(version + "-" + commit)
os.Exit(0)
}
if *imageFlag == "" {
fmt.Fprintln(os.Stderr, "Error: --image flag is required")
os.Exit(1)
}
portStatesJSON := *portStatesJSONFlag
if portStatesJSON == "" {
portStatesJSON = os.Getenv("FRONTPANEL_PORT_STATES_JSON")
}
portLabels := *portLabelsFlag
if !portLabels {
portLabels = frontpanel.ParsePortLabelsValue(os.Getenv("FRONTPANEL_PORT_LABELS"))
}
frontpanel.PrintWithProtocolAndPortStatesAndLabels(
*imageFlag,
*imageProtocolFlag,
frontpanel.ParsePortStatesJSON(portStatesJSON),
portLabels,
)
os.Exit(0)
}