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

Delta Between Two Patch Sets: worker/uniter/jujuc/juju-log.go

Issue 7370043: Change the way aliases to subcommands are handled.
Left Patch Set: Created 12 years, 1 month ago
Right Patch Set: Change the way aliases to subcommands are handled. Created 12 years, 1 month 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 | « worker/uniter/jujuc/config-get.go ('k') | worker/uniter/jujuc/ports.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 "errors" 4 "errors"
5 "launchpad.net/gnuflag" 5 "launchpad.net/gnuflag"
6 "launchpad.net/juju-core/cmd" 6 "launchpad.net/juju-core/cmd"
7 "launchpad.net/juju-core/log" 7 "launchpad.net/juju-core/log"
8 "strings" 8 "strings"
9 ) 9 )
10 10
11 // JujuLogCommand implements the juju-log command. 11 // JujuLogCommand implements the juju-log command.
12 type JujuLogCommand struct { 12 type JujuLogCommand struct {
13 ctx Context 13 ctx Context
14 Message string 14 Message string
15 Debug bool 15 Debug bool
16 Level string // unused 16 Level string // unused
17 } 17 }
18 18
19 func NewJujuLogCommand(ctx Context) cmd.Command { 19 func NewJujuLogCommand(ctx Context) cmd.Command {
20 return &JujuLogCommand{ctx: ctx} 20 return &JujuLogCommand{ctx: ctx}
21 } 21 }
22 22
23 func (c *JujuLogCommand) Info() *cmd.Info { 23 func (c *JujuLogCommand) Info() *cmd.Info {
24 » return cmd.NewInfo("juju-log", "<message>", "write a message to the juju log", "") 24 » return &cmd.Info{
25 » » Name: "juju-log",
26 » » Args: "<message>",
27 » » Purpose: "write a message to the juju log",
28 » }
25 } 29 }
26 30
27 func (c *JujuLogCommand) SetFlags(f *gnuflag.FlagSet) { 31 func (c *JujuLogCommand) SetFlags(f *gnuflag.FlagSet) {
28 f.BoolVar(&c.Debug, "debug", false, "log at debug level") 32 f.BoolVar(&c.Debug, "debug", false, "log at debug level")
29 f.StringVar(&c.Level, "l", "INFO", "Send log message at the given level" ) 33 f.StringVar(&c.Level, "l", "INFO", "Send log message at the given level" )
30 } 34 }
31 35
32 func (c *JujuLogCommand) Init(args []string) error { 36 func (c *JujuLogCommand) Init(args []string) error {
33 if args == nil { 37 if args == nil {
34 return errors.New("no message specified") 38 return errors.New("no message specified")
35 } 39 }
36 c.Message = strings.Join(args, " ") 40 c.Message = strings.Join(args, " ")
37 return nil 41 return nil
38 } 42 }
39 43
40 func (c *JujuLogCommand) Run(_ *cmd.Context) error { 44 func (c *JujuLogCommand) Run(_ *cmd.Context) error {
41 badge := c.ctx.UnitName() 45 badge := c.ctx.UnitName()
42 if r, found := c.ctx.HookRelation(); found { 46 if r, found := c.ctx.HookRelation(); found {
43 badge = badge + " " + r.FakeId() 47 badge = badge + " " + r.FakeId()
44 } 48 }
45 msg := badge + ": " + c.Message 49 msg := badge + ": " + c.Message
46 if c.Debug { 50 if c.Debug {
47 log.Debugf("%s", msg) 51 log.Debugf("%s", msg)
48 } else { 52 } else {
49 log.Printf("%s", msg) 53 log.Printf("%s", msg)
50 } 54 }
51 return nil 55 return nil
52 } 56 }
LEFTRIGHT

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