-
Notifications
You must be signed in to change notification settings - Fork 609
/
mode.go
45 lines (39 loc) · 882 Bytes
/
mode.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
package flagparser
import (
"fmt"
"github.com/moby/swarmkit/v2/api"
"github.com/spf13/pflag"
)
func parseMode(flags *pflag.FlagSet, spec *api.ServiceSpec) error {
if flags.Changed("mode") {
mode, err := flags.GetString("mode")
if err != nil {
return err
}
switch mode {
case "global":
if spec.GetGlobal() == nil {
spec.Mode = &api.ServiceSpec_Global{
Global: &api.GlobalService{},
}
}
case "replicated":
if spec.GetReplicated() == nil {
spec.Mode = &api.ServiceSpec_Replicated{
Replicated: &api.ReplicatedService{},
}
}
}
}
if flags.Changed("replicas") {
if spec.GetReplicated() == nil {
return fmt.Errorf("--replicas can only be specified in --mode replicated")
}
replicas, err := flags.GetUint64("replicas")
if err != nil {
return err
}
spec.GetReplicated().Replicas = replicas
}
return nil
}