github.com/mattyw/juju@v0.0.0-20140610034352-732aecd63861/cmd/juju/removerelation.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  	"github.com/juju/juju/cmd"
    10  	"github.com/juju/juju/cmd/envcmd"
    11  	"github.com/juju/juju/juju"
    12  )
    13  
    14  // RemoveRelationCommand causes an existing service relation to be shut down.
    15  type RemoveRelationCommand struct {
    16  	envcmd.EnvCommandBase
    17  	Endpoints []string
    18  }
    19  
    20  func (c *RemoveRelationCommand) Info() *cmd.Info {
    21  	return &cmd.Info{
    22  		Name:    "remove-relation",
    23  		Args:    "<service1>[:<relation name1>] <service2>[:<relation name2>]",
    24  		Purpose: "remove a relation between two services",
    25  		Aliases: []string{"destroy-relation"},
    26  	}
    27  }
    28  
    29  func (c *RemoveRelationCommand) 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 *RemoveRelationCommand) Run(_ *cmd.Context) error {
    38  	client, err := juju.NewAPIClientFromName(c.EnvName)
    39  	if err != nil {
    40  		return err
    41  	}
    42  	defer client.Close()
    43  	return client.DestroyRelation(c.Endpoints...)
    44  }