Merge lp:~axwalk/juju-core/lp1182898-add-version-flag into lp:~go-bot/juju-core/trunk
Proposed by
Andrew Wilkins
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Andrew Wilkins | ||||
Approved revision: | no longer in the source branch. | ||||
Merged at revision: | 1558 | ||||
Proposed branch: | lp:~axwalk/juju-core/lp1182898-add-version-flag | ||||
Merge into: | lp:~go-bot/juju-core/trunk | ||||
Diff against target: |
180 lines (+97/-10) 2 files modified
cmd/supercommand.go (+36/-10) cmd/supercommand_test.go (+61/-0) |
||||
To merge this branch: | bzr merge lp:~axwalk/juju-core/lp1182898-add-version-flag | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juju Engineering | Pending | ||
Review via email: mp+176849@code.launchpad.net |
Commit message
cmd: Add --version to cmd.SuperCommand
There's no option to control the format;
the sub-command must be used for that.
Description of the change
cmd: Add --version to cmd.SuperCommand
There's no option to control the format;
the sub-command must be used for that.
To post a comment you must log in.
Reviewers: mp+176849_ code.launchpad. net,
Message:
Please take a look.
Description:
cmd: Add --version to cmd.SuperCommand
There's no option to control the format;
the sub-command must be used for that.
https:/ /code.launchpad .net/~axwalk/ juju-core/ lp1182898- add-version- flag/+merge/ 176849
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/11808044/
Affected files: d_test. go
A [revision details]
M cmd/supercommand.go
M cmd/supercomman
Index: [revision details] 20130724165437- wt01mn3gqkwfrel 0
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: tarmac-
+New revision: <email address hidden>
Index: cmd/supercommand.go nd.go'
=== modified file 'cmd/supercomma
--- cmd/supercommand.go 2013-07-10 18:25:42 +0000
+++ cmd/supercommand.go 2013-07-25 03:47:47 +0000
@@ -6,6 +6,7 @@
import (
"bytes"
"fmt"
+ "io/ioutil"
"sort"
"strings"
@@ -65,9 +66,11 @@
Doc string
Log *Log
subcmds map[string]Command
+ commonflags *gnuflag.FlagSet
flags *gnuflag.FlagSet
subcmd Command
showHelp bool
+ showVersion bool
missingCallback MissingCallback
}
@@ -172,15 +175,25 @@
const helpPurpose = "show help on a command or other topic"
-// SetFlags adds the options that apply to all commands, particularly those AddFlags( f) &c.showHelp, "h", false, helpPurpose) &c.showHelp, "help", false, "")
-// due to logging.
-func (c *SuperCommand) SetFlags(f *gnuflag.FlagSet) {
+// setCommonFlags adds the options that apply to all commands,
+// particularly those due to logging.
+func (c *SuperCommand) setCommonFlags(f *gnuflag.FlagSet) {
if c.Log != nil {
c.Log.
}
f.BoolVar(
f.BoolVar(
+ c.commonflags = gnuflag. NewFlagSet( c.Info( ).Name, gnuflag. ContinueOnError ) SetOutput( ioutil. Discard) func(flag *gnuflag.Flag) { Var(flag. Value, flag.Name, flag.Usage) &c.showVersion, "version", false, "Show the version of juju")
+ c.commonflags.
+ f.VisitAll(
+ c.commonflags.
+ })
+}
+
+func (c *SuperCommand) SetFlags(f *gnuflag.FlagSet) {
+ c.setCommonFlags(f)
+ f.BoolVar(
c.flags = f
}
@@ -207,11 +220,11 @@ "unrecognized command: %s %s", c.Name, args[0]) SetFlags( c.flags) SetFlags( c.commonflags) Parse(true, args); err != nil { Args() c.subcmd. Info(). Name}
return fmt.Errorf(
}
args = args[1:]
- c.subcmd.
- if err := c.flags.Parse(true, args); err != nil {
+ c.subcmd.
+ if err := c.commonflags.
return err
}
- args = c.flags.Args()
+ args = c.commonflags.
if c.showHelp {
// We want to treat help for the command the same way we would if we
went "help foo".
args = []string{
@@ -307,7 +320,7 @@
`)
f := gnuflag. NewFlagSet( "", gnuflag. ContinueOnError ) setCommonFlags( f) lts()
- c.super.SetFlags(f)
+ c.super.
f.SetOutput(buf)
f.PrintDefau
return buf.String()
@@ -355,6 +368,13 @@
}
func (c *helpCommand) Run(ctx *Context) error { c.super. flags)
+ if c.super.showVersion {
+ var v VersionCommand
+ v.SetFlags(
+ v.Init([]string{})
+ return v...