Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2834)

Delta Between Two Patch Sets: worker/uniter/jujuc/config-get.go

Issue 7370043: Change the way aliases to subcommands are handled.
Left Patch Set: Created 12 years, 2 months ago
Right Patch Set: Change the way aliases to subcommands are handled. Created 12 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « environs/boilerplate_config.go ('k') | worker/uniter/jujuc/juju-log.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 ctx Context 10 ctx Context
11 Key string // The key to show. If empty, show all. 11 Key string // The key to show. If empty, show all.
12 out cmd.Output 12 out cmd.Output
13 } 13 }
14 14
15 func NewConfigGetCommand(ctx Context) cmd.Command { 15 func NewConfigGetCommand(ctx Context) cmd.Command {
16 return &ConfigGetCommand{ctx: ctx} 16 return &ConfigGetCommand{ctx: ctx}
17 } 17 }
18 18
19 func (c *ConfigGetCommand) Info() *cmd.Info { 19 func (c *ConfigGetCommand) Info() *cmd.Info {
20 » return cmd.NewInfo( 20 » return &cmd.Info{
21 » » "config-get", "[<key>]", 21 » » Name: "config-get",
22 » » "print service configuration", 22 » » Args: "[<key>]",
23 » » "If a key is given, only the value for that key will be printed. ", 23 » » Purpose: "print service configuration",
24 » ) 24 » » Doc: "If a key is given, only the value for that key will be printed.",
25 » }
25 } 26 }
26 27
27 func (c *ConfigGetCommand) SetFlags(f *gnuflag.FlagSet) { 28 func (c *ConfigGetCommand) SetFlags(f *gnuflag.FlagSet) {
28 c.out.AddFlags(f, "smart", cmd.DefaultFormatters) 29 c.out.AddFlags(f, "smart", cmd.DefaultFormatters)
29 } 30 }
30 31
31 func (c *ConfigGetCommand) Init(args []string) error { 32 func (c *ConfigGetCommand) Init(args []string) error {
32 if args == nil { 33 if args == nil {
33 return nil 34 return nil
34 } 35 }
35 c.Key = args[0] 36 c.Key = args[0]
36 return cmd.CheckEmpty(args[1:]) 37 return cmd.CheckEmpty(args[1:])
37 } 38 }
38 39
39 func (c *ConfigGetCommand) Run(ctx *cmd.Context) error { 40 func (c *ConfigGetCommand) Run(ctx *cmd.Context) error {
40 cfg, err := c.ctx.Config() 41 cfg, err := c.ctx.Config()
41 if err != nil { 42 if err != nil {
42 return err 43 return err
43 } 44 }
44 var value interface{} 45 var value interface{}
45 if c.Key == "" { 46 if c.Key == "" {
46 value = cfg 47 value = cfg
47 } else { 48 } else {
48 value, _ = cfg[c.Key] 49 value, _ = cfg[c.Key]
49 } 50 }
50 return c.out.Write(ctx, value) 51 return c.out.Write(ctx, value)
51 } 52 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b