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

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

Issue 7338048: This branch refactors the Command interface.
Patch Set: This branch refactors the Command interface. 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
« no previous file with comments | « cmd/filevar_test.go ('k') | cmd/juju/addrelation_test.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" 5 "launchpad.net/gnuflag"
6 "launchpad.net/juju-core/cmd" 6 "launchpad.net/juju-core/cmd"
7 "launchpad.net/juju-core/juju" 7 "launchpad.net/juju-core/juju"
8 ) 8 )
9 9
10 // AddRelationCommand adds relations between service endpoints. 10 // AddRelationCommand adds relations between service endpoints.
11 type AddRelationCommand struct { 11 type AddRelationCommand struct {
12 EnvName string 12 EnvName string
13 Endpoints []string 13 Endpoints []string
14 } 14 }
15 15
16 func (c *AddRelationCommand) Info() *cmd.Info { 16 func (c *AddRelationCommand) Info() *cmd.Info {
17 return &cmd.Info{ 17 return &cmd.Info{
18 "add-relation", "<service1>[:<relation name1>] <service2>[:<rela tion name2>]", 18 "add-relation", "<service1>[:<relation name1>] <service2>[:<rela tion name2>]",
19 "add a relation between two services", "", 19 "add a relation between two services", "",
20 } 20 }
21 } 21 }
22 22
23 func (c *AddRelationCommand) Init(f *gnuflag.FlagSet, args []string) error { 23 func (c *AddRelationCommand) SetFlags(f *gnuflag.FlagSet) {
24 addEnvironFlags(&c.EnvName, f) 24 addEnvironFlags(&c.EnvName, f)
25 » if err := f.Parse(true, args); err != nil { 25 }
26 » » return err 26
27 » } 27 func (c *AddRelationCommand) Init(args []string) error {
28 » args = f.Args()
29 if len(args) != 2 { 28 if len(args) != 2 {
30 return fmt.Errorf("a relation must involve two services") 29 return fmt.Errorf("a relation must involve two services")
31 } 30 }
32 c.Endpoints = args 31 c.Endpoints = args
33 return nil 32 return nil
34 } 33 }
35 34
36 func (c *AddRelationCommand) Run(_ *cmd.Context) error { 35 func (c *AddRelationCommand) Run(_ *cmd.Context) error {
37 conn, err := juju.NewConnFromName(c.EnvName) 36 conn, err := juju.NewConnFromName(c.EnvName)
38 if err != nil { 37 if err != nil {
39 return err 38 return err
40 } 39 }
41 defer conn.Close() 40 defer conn.Close()
42 eps, err := conn.State.InferEndpoints(c.Endpoints) 41 eps, err := conn.State.InferEndpoints(c.Endpoints)
43 if err != nil { 42 if err != nil {
44 return err 43 return err
45 } 44 }
46 _, err = conn.State.AddRelation(eps...) 45 _, err = conn.State.AddRelation(eps...)
47 return err 46 return err
48 } 47 }
OLDNEW
« no previous file with comments | « cmd/filevar_test.go ('k') | cmd/juju/addrelation_test.go » ('j') | no next file with comments »

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