github.com/mhilton/juju-juju@v0.0.0-20150901100907-a94dd2c73455/cmd/juju/commands/addrelation.go (about) 1 // Copyright 2012, 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package commands 5 6 import ( 7 "fmt" 8 9 "github.com/juju/cmd" 10 11 "github.com/juju/juju/cmd/envcmd" 12 "github.com/juju/juju/cmd/juju/block" 13 ) 14 15 // AddRelationCommand adds a relation between two service endpoints. 16 type AddRelationCommand struct { 17 envcmd.EnvCommandBase 18 Endpoints []string 19 } 20 21 func (c *AddRelationCommand) Info() *cmd.Info { 22 return &cmd.Info{ 23 Name: "add-relation", 24 Args: "<service1>[:<relation name1>] <service2>[:<relation name2>]", 25 Purpose: "add a relation between two services", 26 } 27 } 28 29 func (c *AddRelationCommand) Init(args []string) error { 30 if len(args) != 2 { 31 return fmt.Errorf("a relation must involve two services") 32 } 33 c.Endpoints = args 34 return nil 35 } 36 37 func (c *AddRelationCommand) Run(_ *cmd.Context) error { 38 client, err := c.NewAPIClient() 39 if err != nil { 40 return err 41 } 42 defer client.Close() 43 _, err = client.AddRelation(c.Endpoints...) 44 return block.ProcessBlockedError(err, block.BlockChange) 45 }