-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnset.go
50 lines (42 loc) · 977 Bytes
/
nset.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
package main
import (
"flag"
"fmt"
"os"
"github.com/scgolang/sc"
)
// Nset sets a node's control value.
type Nset struct {
Controls map[string]float32
NodeID int
flagErrorHandling flag.ErrorHandling
scc *sc.Client
}
// Run runs the command.
func (nset Nset) Run(args []string) error {
fs := flag.NewFlagSet("nset", flagErrorHandling)
fs.IntVar(&nset.NodeID, "id", 0, "node ID")
if err := fs.Parse(args); err != nil {
return ErrUsage
}
if nset.NodeID <= 0 {
return ErrUsage
}
if len(fs.Args()) == 0 {
return ErrUsage // Print a usage message if there are no kv pairs.
}
ctls, ok := getSynthControls(fs.Args())
if !ok {
return ErrUsage
}
return nset.scc.NodeSet(int32(nset.NodeID), ctls)
}
// Usage prints a usage message.
func (nset Nset) Usage() {
fmt.Fprint(os.Stderr, `
scc [GLOBAL OPTIONS] nset [OPTIONS] CTL=VALUE [... CTL=VALUE]
OPTIONS
-id (REQUIRED) Node ID.
CTL must be a string and VALUE must be a float.
`)
}