github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/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/cmd"
    10  
    11  	"github.com/juju/juju/cmd/envcmd"
    12  	"github.com/juju/juju/cmd/juju/block"
    13  )
    14  
    15  // RemoveRelationCommand causes an existing service relation to be shut down.
    16  type RemoveRelationCommand struct {
    17  	envcmd.EnvCommandBase
    18  	Endpoints []string
    19  }
    20  
    21  func (c *RemoveRelationCommand) Info() *cmd.Info {
    22  	return &cmd.Info{
    23  		Name:    "remove-relation",
    24  		Args:    "<service1>[:<relation name1>] <service2>[:<relation name2>]",
    25  		Purpose: "remove a relation between two services",
    26  		Aliases: []string{"destroy-relation"},
    27  	}
    28  }
    29  
    30  func (c *RemoveRelationCommand) Init(args []string) error {
    31  	if len(args) != 2 {
    32  		return fmt.Errorf("a relation must involve two services")
    33  	}
    34  	c.Endpoints = args
    35  	return nil
    36  }
    37  
    38  func (c *RemoveRelationCommand) Run(_ *cmd.Context) error {
    39  	client, err := c.NewAPIClient()
    40  	if err != nil {
    41  		return err
    42  	}
    43  	defer client.Close()
    44  	return block.ProcessBlockedError(client.DestroyRelation(c.Endpoints...), block.BlockRemove)
    45  }