| OLD | NEW |
| 1 package jujuc | 1 package jujuc |
| 2 | 2 |
| 3 import ( | 3 import ( |
| 4 "launchpad.net/gnuflag" | 4 "launchpad.net/gnuflag" |
| 5 "launchpad.net/juju-core/cmd" | 5 "launchpad.net/juju-core/cmd" |
| 6 ) | 6 ) |
| 7 | 7 |
| 8 // ConfigGetCommand implements the config-get command. | 8 // ConfigGetCommand implements the config-get command. |
| 9 type ConfigGetCommand struct { | 9 type ConfigGetCommand struct { |
| 10 *HookContext | 10 *HookContext |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 } | 31 } |
| 32 args = f.Args() | 32 args = f.Args() |
| 33 if args == nil { | 33 if args == nil { |
| 34 return nil | 34 return nil |
| 35 } | 35 } |
| 36 c.Key = args[0] | 36 c.Key = args[0] |
| 37 return cmd.CheckEmpty(args[1:]) | 37 return cmd.CheckEmpty(args[1:]) |
| 38 } | 38 } |
| 39 | 39 |
| 40 func (c *ConfigGetCommand) Run(ctx *cmd.Context) error { | 40 func (c *ConfigGetCommand) Run(ctx *cmd.Context) error { |
| 41 » conf, err := c.Service.Config() | 41 » cfg, err := c.Config() |
| 42 if err != nil { | 42 if err != nil { |
| 43 return err | 43 return err |
| 44 } | 44 } |
| 45 charm, _, err := c.Service.Charm() | |
| 46 if err != nil { | |
| 47 return err | |
| 48 } | |
| 49 // TODO Remove this once state is fixed to report default values. | |
| 50 cfg, err := charm.Config().Validate(nil) | |
| 51 if err != nil { | |
| 52 return err | |
| 53 } | |
| 54 cfg = merge(conf.Map(), cfg) | |
| 55 var value interface{} | 45 var value interface{} |
| 56 if c.Key == "" { | 46 if c.Key == "" { |
| 57 value = cfg | 47 value = cfg |
| 58 } else { | 48 } else { |
| 59 value, _ = cfg[c.Key] | 49 value, _ = cfg[c.Key] |
| 60 } | 50 } |
| 61 return c.out.Write(ctx, value) | 51 return c.out.Write(ctx, value) |
| 62 } | 52 } |
| 63 | |
| 64 func merge(a, b map[string]interface{}) map[string]interface{} { | |
| 65 for k, v := range b { | |
| 66 if _, ok := a[k]; !ok { | |
| 67 a[k] = v | |
| 68 } | |
| 69 } | |
| 70 return a | |
| 71 } | |
| OLD | NEW |