github.com/mhilton/juju-juju@v0.0.0-20150901100907-a94dd2c73455/cmd/juju/backups/info.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  
    11  const infoDoc = `
    12  "info" provides the metadata associated with a backup.
    13  `
    14  
    15  // InfoCommand is the sub-command for creating a new backup.
    16  type InfoCommand struct {
    17  	CommandBase
    18  	// ID is the backup ID to get.
    19  	ID string
    20  }
    21  
    22  // Info implements Command.Info.
    23  func (c *InfoCommand) Info() *cmd.Info {
    24  	return &cmd.Info{
    25  		Name:    "info",
    26  		Args:    "<ID>",
    27  		Purpose: "get metadata",
    28  		Doc:     infoDoc,
    29  	}
    30  }
    31  
    32  // Init implements Command.Init.
    33  func (c *InfoCommand) Init(args []string) error {
    34  	if len(args) == 0 {
    35  		return errors.New("missing ID")
    36  	}
    37  	id, args := args[0], args[1:]
    38  	if err := cmd.CheckEmpty(args); err != nil {
    39  		return errors.Trace(err)
    40  	}
    41  	c.ID = id
    42  	return nil
    43  }
    44  
    45  // Run implements Command.Run.
    46  func (c *InfoCommand) Run(ctx *cmd.Context) error {
    47  	client, err := c.NewAPIClient()
    48  	if err != nil {
    49  		return errors.Trace(err)
    50  	}
    51  	defer client.Close()
    52  
    53  	result, err := client.Info(c.ID)
    54  	if err != nil {
    55  		return errors.Trace(err)
    56  	}
    57  
    58  	c.dumpMetadata(ctx, result)
    59  	return nil
    60  }