github.com/mhilton/juju-juju@v0.0.0-20150901100907-a94dd2c73455/worker/uniter/runner/jujuc/storage-list.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package jujuc
     5  
     6  import (
     7  	"github.com/juju/cmd"
     8  	"launchpad.net/gnuflag"
     9  )
    10  
    11  // StorageListCommand implements the storage-list command.
    12  //
    13  // StorageListCommand implements cmd.Command.
    14  type StorageListCommand struct {
    15  	cmd.CommandBase
    16  	ctx Context
    17  	out cmd.Output
    18  }
    19  
    20  func NewStorageListCommand(ctx Context) cmd.Command {
    21  	return &StorageListCommand{ctx: ctx}
    22  }
    23  
    24  func (c *StorageListCommand) Info() *cmd.Info {
    25  	doc := `
    26  storage-list will list the names of all storage instances
    27  attached to the unit. These names can be passed to storage-get
    28  via the "-s" flag to query the storage attributes.
    29  `
    30  	return &cmd.Info{
    31  		Name:    "storage-list",
    32  		Purpose: "list storage attached to the unit",
    33  		Doc:     doc,
    34  	}
    35  }
    36  
    37  func (c *StorageListCommand) SetFlags(f *gnuflag.FlagSet) {
    38  	c.out.AddFlags(f, "smart", cmd.DefaultFormatters)
    39  }
    40  
    41  func (c *StorageListCommand) Init(args []string) (err error) {
    42  	return cmd.CheckEmpty(args)
    43  }
    44  
    45  func (c *StorageListCommand) Run(ctx *cmd.Context) error {
    46  	tags := c.ctx.StorageTags()
    47  	names := make([]string, len(tags))
    48  	for i, tag := range tags {
    49  		names[i] = tag.Id()
    50  	}
    51  	return c.out.Write(ctx, names)
    52  }