~hduran-8/juju-core/trunk

« back to all changes in this revision

Viewing changes to cmd/juju/status.go

  • Committer: Tarmac
  • Author(s): Andrew Wilkins
  • Date: 2014-05-13 01:48:02 UTC
  • mfrom: (2713.1.5 envcmd-inversion)
  • Revision ID: tarmac-20140513014802-d1n958os00gw27zf
[r=axwalk] Invert envcmd relationship

Previously we embedded EnvCommandBase in all commands
requring an environment, and EnvCommandBase included
everything (SetFlags, and Init). The problem with this
is that it was easy to miss initialisation of the
EnvCommandBase type (this happened a few times), which
leads to bad things happening like sync-tools destroying
environments.

I have inverted the relationship so that we now have
envcmd.EnvironCommand, an interface that extends Command
with a SetEnvName method, and EnvCommandBase, which
implements EnvironCommand. A new method, envcmd.Wrap takes
an EnvironCommand and creates a Command that calls
SetEnvName prior to the wrapped method's Init method. If
the environment name cannot be determined, the wrapping
command will error out early.

https://codereview.appspot.com/94350045/

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
}
51
51
 
52
52
func (c *StatusCommand) SetFlags(f *gnuflag.FlagSet) {
53
 
        c.EnvCommandBase.SetFlags(f)
54
53
        c.out.AddFlags(f, "yaml", map[string]cmd.Formatter{
55
54
                "yaml": cmd.FormatYaml,
56
55
                "json": cmd.FormatJson,
58
57
}
59
58
 
60
59
func (c *StatusCommand) Init(args []string) error {
61
 
        if err := c.EnvCommandBase.EnsureEnvName(); err != nil {
62
 
                return err
63
 
        }
64
60
        c.patterns = args
65
61
        return nil
66
62
}