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