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