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

Side by Side Diff: cmd/juju/addrelation.go

Issue 7375053: Add a composed base class for commands.
Patch Set: Add a composed base class for commands. 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:
View unified diff | Download patch
« cmd/cmd.go ('K') | « cmd/cmd.go ('k') | cmd/juju/addunit.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 package main 1 package main
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "launchpad.net/gnuflag"
6 "launchpad.net/juju-core/cmd" 5 "launchpad.net/juju-core/cmd"
7 "launchpad.net/juju-core/juju" 6 "launchpad.net/juju-core/juju"
8 ) 7 )
9 8
10 // AddRelationCommand adds relations between service endpoints. 9 // AddRelationCommand adds relations between service endpoints.
11 type AddRelationCommand struct { 10 type AddRelationCommand struct {
12 » EnvName string 11 » EnvCommandBase
dimitern 2013/02/28 09:10:55 Why?
13 Endpoints []string 12 Endpoints []string
14 } 13 }
15 14
16 func (c *AddRelationCommand) Info() *cmd.Info { 15 func (c *AddRelationCommand) Info() *cmd.Info {
17 return &cmd.Info{ 16 return &cmd.Info{
18 Name: "add-relation", 17 Name: "add-relation",
19 Args: "<service1>[:<relation name1>] <service2>[:<relation na me2>]", 18 Args: "<service1>[:<relation name1>] <service2>[:<relation na me2>]",
20 Purpose: "add a relation between two services", 19 Purpose: "add a relation between two services",
21 } 20 }
22 } 21 }
23 22
24 func (c *AddRelationCommand) SetFlags(f *gnuflag.FlagSet) {
dimitern 2013/02/28 09:10:55 Why is this removed? And the EnvName up there?
rog 2013/02/28 12:31:57 i see why it's removed (EnvCommandBase.SetFlags ad
25 addEnvironFlags(&c.EnvName, f)
26 }
27
28 func (c *AddRelationCommand) Init(args []string) error { 23 func (c *AddRelationCommand) Init(args []string) error {
29 if len(args) != 2 { 24 if len(args) != 2 {
30 return fmt.Errorf("a relation must involve two services") 25 return fmt.Errorf("a relation must involve two services")
31 } 26 }
32 c.Endpoints = args 27 c.Endpoints = args
33 return nil 28 return nil
34 } 29 }
35 30
36 func (c *AddRelationCommand) Run(_ *cmd.Context) error { 31 func (c *AddRelationCommand) Run(_ *cmd.Context) error {
37 conn, err := juju.NewConnFromName(c.EnvName) 32 conn, err := juju.NewConnFromName(c.EnvName)
38 if err != nil { 33 if err != nil {
39 return err 34 return err
40 } 35 }
41 defer conn.Close() 36 defer conn.Close()
42 eps, err := conn.State.InferEndpoints(c.Endpoints) 37 eps, err := conn.State.InferEndpoints(c.Endpoints)
43 if err != nil { 38 if err != nil {
44 return err 39 return err
45 } 40 }
46 _, err = conn.State.AddRelation(eps...) 41 _, err = conn.State.AddRelation(eps...)
47 return err 42 return err
48 } 43 }
OLDNEW
« cmd/cmd.go ('K') | « cmd/cmd.go ('k') | cmd/juju/addunit.go » ('j') | no next file with comments »

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