LEFT | RIGHT |
(no file at all) | |
1 package main | 1 package main |
2 | 2 |
3 import ( | 3 import ( |
4 "fmt" | 4 "fmt" |
5 "launchpad.net/gnuflag" | 5 "launchpad.net/gnuflag" |
| 6 "launchpad.net/juju/go/cmd" |
6 "launchpad.net/juju/go/juju" | 7 "launchpad.net/juju/go/juju" |
7 ) | 8 ) |
8 | 9 |
9 // UnitAgent is a cmd.Command responsible for running a unit agent. | 10 // UnitAgent is a cmd.Command responsible for running a unit agent. |
10 type UnitAgent struct { | 11 type UnitAgent struct { |
11 agentConf | 12 agentConf |
12 UnitName string | 13 UnitName string |
13 } | 14 } |
14 | 15 |
15 func NewUnitAgent() *UnitAgent { | 16 func NewUnitAgent() *UnitAgent { |
16 return &UnitAgent{agentConf: agentConf{name: "unit"}} | 17 return &UnitAgent{agentConf: agentConf{name: "unit"}} |
17 } | 18 } |
18 | 19 |
19 // InitFlagSet prepares a FlagSet. | 20 // Init initializes the command for running. |
20 func (a *UnitAgent) InitFlagSet(f *gnuflag.FlagSet) { | 21 func (a *UnitAgent) Init(f *gnuflag.FlagSet, args []string) error { |
21 f.StringVar(&a.UnitName, "unit-name", "", "name of the unit to run") | 22 f.StringVar(&a.UnitName, "unit-name", "", "name of the unit to run") |
22 » a.agentConf.InitFlagSet(f) | 23 » if err := a.agentConf.Init(f, args); err != nil { |
23 } | 24 » » return err |
24 | 25 » } |
25 // ParsePositional checks that there are no unwanted arguments, and that all | |
26 // required flags have been set. | |
27 func (a *UnitAgent) ParsePositional(args []string) error { | |
28 if a.UnitName == "" { | 26 if a.UnitName == "" { |
29 return requiredError("unit-name") | 27 return requiredError("unit-name") |
30 } | 28 } |
31 if !juju.ValidUnit.MatchString(a.UnitName) { | 29 if !juju.ValidUnit.MatchString(a.UnitName) { |
32 return fmt.Errorf(`--unit-name option expects "<service>/<n>" ar
gument`) | 30 return fmt.Errorf(`--unit-name option expects "<service>/<n>" ar
gument`) |
33 } | 31 } |
34 » return a.agentConf.ParsePositional(args) | 32 » return nil |
35 } | 33 } |
36 | 34 |
37 // Run runs a unit agent. | 35 // Run runs a unit agent. |
38 func (a *UnitAgent) Run() error { | 36 func (a *UnitAgent) Run(_ *cmd.Context) error { |
39 return fmt.Errorf("UnitAgent.Run not implemented") | 37 return fmt.Errorf("UnitAgent.Run not implemented") |
40 } | 38 } |
LEFT | RIGHT |