5
"launchpad.net/gnuflag"
6
"launchpad.net/juju/go/cmd"
9
// ConfigGetCommand implements the config-get command.
10
type ConfigGetCommand struct {
12
Key string // The key to show. If empty, show all.
16
func NewConfigGetCommand(ctx *ClientContext) (cmd.Command, error) {
18
return nil, fmt.Errorf("context %s cannot access state", ctx.Id)
20
if ctx.LocalUnitName == "" {
21
return nil, fmt.Errorf("context %s is not attached to a unit", ctx.Id)
23
return &ConfigGetCommand{ClientContext: ctx}, nil
26
func (c *ConfigGetCommand) Info() *cmd.Info {
28
"config-get", "[<key>]",
29
"print service configuration",
30
"If a key is given, only the value for that key will be printed.",
34
func (c *ConfigGetCommand) Init(f *gnuflag.FlagSet, args []string) error {
35
c.out.addFlags(f, "smart", defaultConverters)
36
if err := f.Parse(true, args); err != nil {
44
return cmd.CheckEmpty(args[1:])
47
func (c *ConfigGetCommand) Run(ctx *cmd.Context) error {
48
unit, err := c.State.Unit(c.LocalUnitName)
52
service, err := c.State.Service(unit.ServiceName())
56
conf, err := service.Config()
64
value, _ = conf.Get(c.Key)
66
return c.out.write(ctx, value)