github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/cmd/juju/commands/resolved.go (about) 1 // Copyright 2012, 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package commands 5 6 import ( 7 "fmt" 8 9 "github.com/juju/cmd" 10 "github.com/juju/names" 11 "launchpad.net/gnuflag" 12 13 "github.com/juju/juju/cmd/juju/block" 14 "github.com/juju/juju/cmd/modelcmd" 15 ) 16 17 func newResolvedCommand() cmd.Command { 18 return modelcmd.Wrap(&resolvedCommand{}) 19 } 20 21 // resolvedCommand marks a unit in an error state as ready to continue. 22 type resolvedCommand struct { 23 modelcmd.ModelCommandBase 24 UnitName string 25 Retry bool 26 } 27 28 func (c *resolvedCommand) Info() *cmd.Info { 29 return &cmd.Info{ 30 Name: "resolved", 31 Args: "<unit>", 32 Purpose: "marks unit errors resolved", 33 } 34 } 35 36 func (c *resolvedCommand) SetFlags(f *gnuflag.FlagSet) { 37 f.BoolVar(&c.Retry, "r", false, "re-execute failed hooks") 38 f.BoolVar(&c.Retry, "retry", false, "") 39 } 40 41 func (c *resolvedCommand) Init(args []string) error { 42 if len(args) > 0 { 43 c.UnitName = args[0] 44 if !names.IsValidUnit(c.UnitName) { 45 return fmt.Errorf("invalid unit name %q", c.UnitName) 46 } 47 args = args[1:] 48 } else { 49 return fmt.Errorf("no unit specified") 50 } 51 return cmd.CheckEmpty(args) 52 } 53 54 func (c *resolvedCommand) Run(_ *cmd.Context) error { 55 client, err := c.NewAPIClient() 56 if err != nil { 57 return err 58 } 59 defer client.Close() 60 return block.ProcessBlockedError(client.Resolved(c.UnitName, c.Retry), block.BlockChange) 61 }