1
// Copyright 2012, 2013 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
10
"github.com/juju/errors"
11
"launchpad.net/gnuflag"
14
// UnitGetCommand implements the unit-get command.
15
type UnitGetCommand struct {
22
func NewUnitGetCommand(ctx Context) (cmd.Command, error) {
23
return &UnitGetCommand{ctx: ctx}, nil
26
func (c *UnitGetCommand) Info() *cmd.Info {
30
Purpose: "print public-address or private-address",
34
func (c *UnitGetCommand) SetFlags(f *gnuflag.FlagSet) {
35
c.out.AddFlags(f, "smart", cmd.DefaultFormatters)
38
func (c *UnitGetCommand) Init(args []string) error {
40
return errors.New("no setting specified")
42
if args[0] != "private-address" && args[0] != "public-address" {
43
return fmt.Errorf("unknown setting %q", args[0])
46
return cmd.CheckEmpty(args[1:])
49
func (c *UnitGetCommand) Run(ctx *cmd.Context) error {
52
if c.Key == "private-address" {
53
value, err = c.ctx.PrivateAddress()
55
value, err = c.ctx.PublicAddress()
58
return errors.Trace(err)
60
return c.out.Write(ctx, value)