github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/cmd/juju/backups/show.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 "github.com/juju/cmd" 8 "github.com/juju/errors" 9 10 "github.com/juju/juju/cmd/modelcmd" 11 ) 12 13 const showDoc = ` 14 show-backup provides the metadata associated with a backup. 15 ` 16 17 // NewShowCommand returns a command used to show metadata for a backup. 18 func NewShowCommand() cmd.Command { 19 return modelcmd.Wrap(&showCommand{}) 20 } 21 22 // showCommand is the sub-command for creating a new backup. 23 type showCommand struct { 24 CommandBase 25 // ID is the backup ID to get. 26 ID string 27 } 28 29 // Info implements Command.Info. 30 func (c *showCommand) Info() *cmd.Info { 31 return &cmd.Info{ 32 Name: "show-backup", 33 Args: "<ID>", 34 Purpose: "Show metadata for the specified backup.", 35 Doc: showDoc, 36 } 37 } 38 39 // Init implements Command.Init. 40 func (c *showCommand) Init(args []string) error { 41 if len(args) == 0 { 42 return errors.New("missing ID") 43 } 44 id, args := args[0], args[1:] 45 if err := cmd.CheckEmpty(args); err != nil { 46 return errors.Trace(err) 47 } 48 c.ID = id 49 return nil 50 } 51 52 // Run implements Command.Run. 53 func (c *showCommand) Run(ctx *cmd.Context) error { 54 if c.Log != nil { 55 if err := c.Log.Start(ctx); err != nil { 56 return err 57 } 58 } 59 client, err := c.NewAPIClient() 60 if err != nil { 61 return errors.Trace(err) 62 } 63 defer client.Close() 64 65 result, err := client.Info(c.ID) 66 if err != nil { 67 return errors.Trace(err) 68 } 69 70 c.dumpMetadata(ctx, result) 71 return nil 72 }