launchpad.net/~rogpeppe/juju-core/500-errgo-fix@v0.0.0-20140213181702-000000002356/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 "launchpad.net/errgo/errors" 8 9 "launchpad.net/gnuflag" 10 11 "launchpad.net/juju-core/cmd" 12 ) 13 14 // OwnerGetCommand implements the owner-get command. 15 type OwnerGetCommand struct { 16 cmd.CommandBase 17 ctx Context 18 Key string 19 out cmd.Output 20 } 21 22 func NewOwnerGetCommand(ctx Context) cmd.Command { 23 return &OwnerGetCommand{ctx: ctx} 24 } 25 26 func (c *OwnerGetCommand) Info() *cmd.Info { 27 return &cmd.Info{ 28 Name: "owner-get", 29 Args: "<setting>", 30 Purpose: `print information about the owner of the service. The only valid value for <setting> is currently tag`, 31 } 32 } 33 34 func (c *OwnerGetCommand) SetFlags(f *gnuflag.FlagSet) { 35 c.out.AddFlags(f, "smart", cmd.DefaultFormatters) 36 } 37 38 func (c *OwnerGetCommand) Init(args []string) error { 39 if args == nil { 40 return errors.New("no setting specified") 41 } 42 if args[0] != "tag" { 43 return errors.Newf("unknown setting %q", args[0]) 44 } 45 c.Key = args[0] 46 return cmd.CheckEmpty(args[1:]) 47 } 48 49 func (c *OwnerGetCommand) Run(ctx *cmd.Context) error { 50 if c.Key != "tag" { 51 return errors.Newf("%s not set", c.Key) 52 } 53 54 return c.out.Write(ctx, c.ctx.OwnerTag()) 55 }