~juju-qa/ubuntu/xenial/juju/2.0-rc2

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/cmd/juju/application/removerelation.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
 
40
40
// NewRemoveRelationCommand returns a command to remove a relation between 2 services.
41
41
func NewRemoveRelationCommand() cmd.Command {
42
 
        return modelcmd.Wrap(&removeRelationCommand{})
 
42
        cmd := &removeRelationCommand{}
 
43
        cmd.newAPIFunc = func() (ApplicationDestroyRelationAPI, error) {
 
44
                root, err := cmd.NewAPIRoot()
 
45
                if err != nil {
 
46
                        return nil, errors.Trace(err)
 
47
                }
 
48
                return application.NewClient(root), nil
 
49
 
 
50
        }
 
51
        return modelcmd.Wrap(cmd)
43
52
}
44
53
 
45
54
// removeRelationCommand causes an existing application relation to be shut down.
46
55
type removeRelationCommand struct {
47
56
        modelcmd.ModelCommandBase
48
 
        Endpoints []string
 
57
        Endpoints  []string
 
58
        newAPIFunc func() (ApplicationDestroyRelationAPI, error)
49
59
}
50
60
 
51
61
func (c *removeRelationCommand) Info() *cmd.Info {
65
75
        return nil
66
76
}
67
77
 
68
 
type serviceDestroyRelationAPI interface {
 
78
// ApplicationDestroyRelationAPI defines the API methods that application remove relation command uses.
 
79
type ApplicationDestroyRelationAPI interface {
69
80
        Close() error
70
81
        DestroyRelation(endpoints ...string) error
71
82
}
72
83
 
73
 
func (c *removeRelationCommand) getAPI() (serviceDestroyRelationAPI, error) {
74
 
        root, err := c.NewAPIRoot()
75
 
        if err != nil {
76
 
                return nil, errors.Trace(err)
77
 
        }
78
 
        return application.NewClient(root), nil
79
 
}
80
 
 
81
84
func (c *removeRelationCommand) Run(_ *cmd.Context) error {
82
 
        client, err := c.getAPI()
 
85
        client, err := c.newAPIFunc()
83
86
        if err != nil {
84
87
                return err
85
88
        }