-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
165 lines (149 loc) · 4.6 KB
/
example_test.go
File metadata and controls
165 lines (149 loc) · 4.6 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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package verbs_test
import (
"fmt"
"os"
"github.com/revl/verbs"
)
const programDescription = "" +
"LightForge CLI is a command-line interface designed to control " +
"architectural lighting systems in large installations such as " +
"museums, hotels, and plazas. It allows lighting designers and " +
"technicians to manage zones, colors, intensity, and automation " +
"scenes directly from a terminal."
var tutorialText = programDescription + "\n\n" +
"Connecting to a Lighting Controller\n" +
"===================================\n\n" +
"Before issuing control commands, connect to the central controller " +
"on your network:\n\n" +
" $ lightforge connect 192.168.1.15:5020\n\n" +
"Adjusting Lighting Settings\n" +
"===========================\n\n" +
"Zones are the basic units of lighting control. Each zone can be " +
"assigned a color, intensity, and automation scene. To list " +
"available zones, use the `list` command:\n\n" +
" $ lightforge zones list\n\n" +
"To set the intensity of the \"Lobby\" zone to 75% and the color " +
"to red:\n\n" +
" $ lightforge zone set Lobby --intensity 75 --color red\n\n" +
"Creating and Running Scenes\n" +
"===========================\n\n" +
"Scenes store multiple settings for quick recall:\n\n" +
" $ lightforge scene create \"Evening Ambience\" \\\n" +
" --zone Lobby --zone Gallery \\\n" +
" --intensity 60 --color 220,180,150\n\n" +
"To activate it later:\n\n" +
" $ lightforge scene activate \"Evening Ambience\"\n\n" +
"For more information, run `lightforge help COMMAND` or\n" +
"`lightforge COMMAND --help`."
type Args map[string][]string
var connectCommand = &verbs.Command{
Name: "connect",
Summary: "Connect to a lighting system controller",
Description: "Connect to the lighting system controller " +
"using the provided host and port",
Args: []*verbs.Arg{{Name: "ADDRESS"}},
Tag: func(args Args) {
fmt.Printf("Connecting to %s...\n", args["ADDRESS"][0])
},
}
var zoneListCommand = &verbs.Command{
Name: "list",
Summary: "List available zones",
Description: "This command lists all zones registered " +
"with the controller",
Tag: func(_ Args) { fmt.Println("Listing zones...") },
}
var intensityOption = &verbs.Option{
Name: "i|intensity",
Param: "PERCENTAGE",
Description: "The brightness of the zone",
Tag: "intensity",
}
var colorOption = &verbs.Option{
Name: "c|color",
Param: "COLOR",
Description: "The color of the zone",
Tag: "color",
}
var zoneSetCommand = &verbs.Command{
Name: "set",
Summary: "Change zone settings",
Description: "This command sets one or more properties of a zone",
Options: []*verbs.Option{
intensityOption,
colorOption,
},
Args: []*verbs.Arg{{Name: "ZONE"}},
Tag: func(args Args) {
fmt.Printf("Changing zone settings... %s\n", args["ZONE"][0])
},
}
var sceneCreateCommand = &verbs.Command{
Name: "create",
Summary: "Create a new scene",
Description: "This command creates a new scene with the given " +
"name and settings",
Options: []*verbs.Option{
{
Name: "zones|zone",
Param: "ZONE",
Description: "The zone to create the scene for. " +
"Multiple zones can be specified " +
"by repeating the option.",
Tag: "zone",
},
intensityOption,
colorOption,
},
Args: []*verbs.Arg{{Name: "NAME"}},
Tag: func(args Args) {
fmt.Printf("Creating scene %s...\n", args["NAME"][0])
fmt.Println("Zones:", args["zone"])
},
}
var sceneActivateCommand = &verbs.Command{
Name: "activate",
Summary: "Activate a scene",
Description: "This command activates a scene with the given name",
Args: []*verbs.Arg{{Name: "NAME"}},
Tag: func(args Args) {
fmt.Printf("Activating scene %s...\n", args["NAME"][0])
},
}
var lightforgeCLI = &verbs.CLI{
ProgramName: "lightforge",
Summary: "LightForge remote light management CLI",
Description: programDescription,
Version: "1.0.0",
Namespaces: []*verbs.Namespace{
{
Name: "zones|zone",
Summary: "Zone management",
Commands: []*verbs.Command{
zoneListCommand,
zoneSetCommand,
},
},
{
Name: "scenes|scene",
Summary: "Scene management",
Commands: []*verbs.Command{
sceneCreateCommand,
sceneActivateCommand,
},
},
},
Commands: []*verbs.Command{connectCommand},
HelpTopics: []*verbs.HelpTopic{
{Keyword: "tutorial", Text: tutorialText},
},
}
func Example() {
result := verbs.NewParser(lightforgeCLI).Parse(os.Args)
args := make(Args)
for _, arg := range result.OptsAndArgs {
args[arg.Tag.(string)] = append(args[arg.Tag.(string)],
arg.Value)
}
(result.Command.Tag).(func(Args))(args)
}