github.com/mattyw/juju@v0.0.0-20140610034352-732aecd63861/worker/uniter/jujuc/owner-get.go (about) 1 // Copyright 2012, 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package jujuc 5 6 import ( 7 "errors" 8 "fmt" 9 10 "launchpad.net/gnuflag" 11 12 "github.com/juju/juju/cmd" 13 ) 14 15 // OwnerGetCommand implements the owner-get command. 16 type OwnerGetCommand struct { 17 cmd.CommandBase 18 ctx Context 19 Key string 20 out cmd.Output 21 } 22 23 func NewOwnerGetCommand(ctx Context) cmd.Command { 24 return &OwnerGetCommand{ctx: ctx} 25 } 26 27 func (c *OwnerGetCommand) Info() *cmd.Info { 28 return &cmd.Info{ 29 Name: "owner-get", 30 Args: "<setting>", 31 Purpose: `print information about the owner of the service. The only valid value for <setting> is currently tag`, 32 } 33 } 34 35 func (c *OwnerGetCommand) SetFlags(f *gnuflag.FlagSet) { 36 c.out.AddFlags(f, "smart", cmd.DefaultFormatters) 37 } 38 39 func (c *OwnerGetCommand) Init(args []string) error { 40 if args == nil { 41 return errors.New("no setting specified") 42 } 43 if args[0] != "tag" { 44 return fmt.Errorf("unknown setting %q", args[0]) 45 } 46 c.Key = args[0] 47 return cmd.CheckEmpty(args[1:]) 48 } 49 50 func (c *OwnerGetCommand) Run(ctx *cmd.Context) error { 51 if c.Key != "tag" { 52 return fmt.Errorf("%s not set", c.Key) 53 } 54 55 return c.out.Write(ctx, c.ctx.OwnerTag()) 56 }