github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/cmd/juju/cloud/remove.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package cloud 5 6 import ( 7 "github.com/juju/cmd" 8 "github.com/juju/errors" 9 10 "github.com/juju/juju/cloud" 11 ) 12 13 var usageRemoveCloudSummary = ` 14 Removes a user-defined cloud from Juju.`[1:] 15 16 var usageRemoveCloudDetails = ` 17 Remove a named, user-defined cloud from Juju. 18 19 Examples: 20 juju remove-cloud mycloud 21 22 See also: 23 add-cloud 24 list-clouds` 25 26 type removeCloudCommand struct { 27 cmd.CommandBase 28 29 // Cloud is the name fo the cloud to remove. 30 Cloud string 31 } 32 33 // NewRemoveCloudCommand returns a command to remove cloud information. 34 func NewRemoveCloudCommand() cmd.Command { 35 return &removeCloudCommand{} 36 } 37 38 func (c *removeCloudCommand) Info() *cmd.Info { 39 return &cmd.Info{ 40 Name: "remove-cloud", 41 Args: "<cloud name>", 42 Purpose: usageRemoveCloudSummary, 43 Doc: usageRemoveCloudDetails, 44 } 45 } 46 47 func (c *removeCloudCommand) Init(args []string) (err error) { 48 if len(args) < 1 { 49 return errors.New("Usage: juju remove-cloud <cloud name>") 50 } 51 c.Cloud = args[0] 52 return cmd.CheckEmpty(args[1:]) 53 } 54 55 func (c *removeCloudCommand) Run(ctxt *cmd.Context) error { 56 personalClouds, err := cloud.PersonalCloudMetadata() 57 if err != nil { 58 return err 59 } 60 if _, ok := personalClouds[c.Cloud]; !ok { 61 ctxt.Infof("No personal cloud called %q exists", c.Cloud) 62 return nil 63 } 64 delete(personalClouds, c.Cloud) 65 if err := cloud.WritePersonalCloudMetadata(personalClouds); err != nil { 66 return errors.Trace(err) 67 } 68 ctxt.Infof("Removed details of personal cloud %q", c.Cloud) 69 return nil 70 }