forked from fluxcd/flux
/
lock_cmd.go
45 lines (37 loc) · 932 Bytes
/
lock_cmd.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 main
import (
"github.com/spf13/cobra"
"github.com/weaveworks/flux"
)
type serviceLockOpts struct {
*serviceOpts
service string
}
func newServiceLock(parent *serviceOpts) *serviceLockOpts {
return &serviceLockOpts{serviceOpts: parent}
}
func (opts *serviceLockOpts) Command() *cobra.Command {
cmd := &cobra.Command{
Use: "lock",
Short: "Lock a service, so it cannot be deployed.",
Example: makeExample(
"fluxctl lock --service=helloworld",
),
RunE: opts.RunE,
}
cmd.Flags().StringVarP(&opts.service, "service", "s", "", "Service to lock")
return cmd
}
func (opts *serviceLockOpts) RunE(_ *cobra.Command, args []string) error {
if len(args) > 0 {
return errorWantedNoArgs
}
if opts.service == "" {
return newUsageError("-s, --service is required")
}
serviceID, err := flux.ParseServiceID(opts.service)
if err != nil {
return err
}
return opts.API.Lock(noInstanceID, serviceID)
}