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