github.com/mhilton/juju-juju@v0.0.0-20150901100907-a94dd2c73455/cmd/juju/backups/remove.go (about) 1 // Copyright 2014 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package backups 5 6 import ( 7 "fmt" 8 9 "github.com/juju/cmd" 10 "github.com/juju/errors" 11 ) 12 13 const removeDoc = ` 14 "remove" removes a backup from remote storage. 15 ` 16 17 // CreateCommand is the sub-command for creating a new backup. 18 type RemoveCommand struct { 19 CommandBase 20 // ID refers to the backup to be removed. 21 ID string 22 } 23 24 // Info implements Command.Info. 25 func (c *RemoveCommand) Info() *cmd.Info { 26 return &cmd.Info{ 27 Name: "remove", 28 Args: "<ID>", 29 Purpose: "delete a backup", 30 Doc: removeDoc, 31 } 32 } 33 34 // Init implements Command.Init. 35 func (c *RemoveCommand) Init(args []string) error { 36 if len(args) == 0 { 37 return errors.New("missing ID") 38 } 39 id, args := args[0], args[1:] 40 if err := cmd.CheckEmpty(args); err != nil { 41 return errors.Trace(err) 42 } 43 c.ID = id 44 return nil 45 } 46 47 // Run implements Command.Run. 48 func (c *RemoveCommand) Run(ctx *cmd.Context) error { 49 client, err := c.NewAPIClient() 50 if err != nil { 51 return errors.Trace(err) 52 } 53 defer client.Close() 54 55 err = client.Remove(c.ID) 56 if err != nil { 57 return errors.Trace(err) 58 } 59 60 fmt.Fprintln(ctx.Stdout, "successfully removed:", c.ID) 61 return nil 62 }