1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
8
"github.com/juju/errors"
9
"launchpad.net/gnuflag"
12
// isLeaderCommand implements the is-leader command.
13
type isLeaderCommand struct {
19
// NewIsLeaderCommand returns a new isLeaderCommand with the given context.
20
func NewIsLeaderCommand(ctx Context) (cmd.Command, error) {
21
return &isLeaderCommand{ctx: ctx}, nil
24
// Info is part of the cmd.Command interface.
25
func (c *isLeaderCommand) Info() *cmd.Info {
27
is-leader prints a boolean indicating whether the local unit is guaranteed to
28
be service leader for at least 30 seconds. If it fails, you should assume that
29
there is no such guarantee.
33
Purpose: "print service leadership status",
38
// SetFlags is part of the cmd.Command interface.
39
func (c *isLeaderCommand) SetFlags(f *gnuflag.FlagSet) {
40
c.out.AddFlags(f, "smart", cmd.DefaultFormatters)
43
// Run is part of the cmd.Command interface.
44
func (c *isLeaderCommand) Run(ctx *cmd.Context) error {
45
success, err := c.ctx.IsLeader()
47
return errors.Annotatef(err, "leadership status unknown")
49
return c.out.Write(ctx, success)