-
Notifications
You must be signed in to change notification settings - Fork 491
/
leader-set.go
51 lines (43 loc) · 1.44 KB
/
leader-set.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
51
// Copyright 2015 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package jujuc
import (
"github.com/juju/cmd/v3"
"github.com/juju/errors"
"github.com/juju/utils/v3/keyvalues"
jujucmd "github.com/juju/juju/cmd"
)
// leaderSetCommand implements the leader-set command.
type leaderSetCommand struct {
cmd.CommandBase
ctx Context
settings map[string]string
}
// NewLeaderSetCommand returns a new leaderSetCommand with the given context.
func NewLeaderSetCommand(ctx Context) (cmd.Command, error) {
return &leaderSetCommand{ctx: ctx}, nil
}
// Info is part of the cmd.Command interface.
func (c *leaderSetCommand) Info() *cmd.Info {
doc := `
leader-set immediate writes the supplied key/value pairs to the controller,
which will then inform non-leader units of the change. It will fail if called
without arguments, or if called by a unit that is not currently application leader.
`
return jujucmd.Info(&cmd.Info{
Name: "leader-set",
Args: "<key>=<value> [...]",
Purpose: "write application leadership settings",
Doc: doc,
})
}
// Init is part of the cmd.Command interface.
func (c *leaderSetCommand) Init(args []string) (err error) {
c.settings, err = keyvalues.Parse(args, true)
return
}
// Run is part of the cmd.Command interface.
func (c *leaderSetCommand) Run(_ *cmd.Context) error {
err := c.ctx.WriteLeaderSettings(c.settings)
return errors.Annotatef(err, "cannot write leadership settings")
}