~fwereade/pyjuju/go-log-type

« back to all changes in this revision

Viewing changes to cmd/jujud/machine.go

  • Committer: William Reade
  • Author(s): William Reade
  • Date: 2012-02-17 09:22:47 UTC
  • mfrom: (61.1.1 go)
  • Revision ID: fwereade@gmail.com-20120217092247-bs9zhqak1w3uzkzr
add jujud command (with subcommands initzk, unit, machine, provisioning)

Moved some of cmd/juju into cmd, with some changes, for reuse by cmd/jujud;
added subcommands listed above. None of these commands actually do anything
yet; I'm waiting for the State connection work to stabilise a bit before I
hook this up.

It's interesting to note that SuperCommand (once JujuCommand) needs only a
little work before it can itself usefully Register further SuperCommands, but
there's no call for that at the moment (we'd need to add a managesLogging
field which, if unset, would block initOutput and prevent InitFlagSet from
trying to extend the subcommand, and set it only on the top-level command).

The various agent types now implement cmd.Command by embedding agentConf;
and, indeed, it's even nicer like this :).

R=rog, niemeyer
CC=
https://codereview.appspot.com/5642048

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package main
 
2
 
 
3
import (
 
4
        "fmt"
 
5
        "launchpad.net/gnuflag"
 
6
)
 
7
 
 
8
// MachineAgent is a cmd.Command responsible for running a machine agent.
 
9
type MachineAgent struct {
 
10
        agentConf
 
11
        MachineId int
 
12
}
 
13
 
 
14
func NewMachineAgent() *MachineAgent {
 
15
        return &MachineAgent{agentConf: agentConf{name: "machine"}}
 
16
}
 
17
 
 
18
// InitFlagSet prepares a FlagSet.
 
19
func (a *MachineAgent) InitFlagSet(f *gnuflag.FlagSet) {
 
20
        f.IntVar(&a.MachineId, "machine-id", -1, "id of the machine to run")
 
21
        a.agentConf.InitFlagSet(f)
 
22
}
 
23
 
 
24
// ParsePositional checks that there are no unwanted arguments, and that all
 
25
// required flags have been set.
 
26
func (a *MachineAgent) ParsePositional(args []string) error {
 
27
        if a.MachineId < 0 {
 
28
                return fmt.Errorf("--machine-id option must be set, and expects a non-negative integer")
 
29
        }
 
30
        return a.agentConf.ParsePositional(args)
 
31
}
 
32
 
 
33
// Run runs a machine agent.
 
34
func (a *MachineAgent) Run() error {
 
35
        return fmt.Errorf("MachineAgent.Run not implemented")
 
36
}