github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/cmd/juju/charms/charms.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package charms
     5  
     6  import (
     7  	"github.com/juju/cmd"
     8  	"github.com/juju/loggo"
     9  
    10  	"github.com/juju/juju/api/charms"
    11  	"github.com/juju/juju/cmd/envcmd"
    12  )
    13  
    14  var logger = loggo.GetLogger("juju.cmd.juju.charms")
    15  
    16  const charmsCommandDoc = `
    17  "juju charms" is used to manage the charms in the Juju environment.
    18  `
    19  
    20  const charmsCommandPurpose = "manage charms"
    21  
    22  // NewSuperCommand creates the charms supercommand and registers the subcommands
    23  // that it supports.
    24  func NewSuperCommand() cmd.Command {
    25  	charmscmd := cmd.NewSuperCommand(cmd.SuperCommandParams{
    26  		Name:        "charms",
    27  		Doc:         charmsCommandDoc,
    28  		UsagePrefix: "juju",
    29  		Purpose:     charmsCommandPurpose,
    30  	})
    31  	charmscmd.Register(envcmd.Wrap(&ListCommand{}))
    32  	return charmscmd
    33  }
    34  
    35  // CharmsCommandBase is a helper base structure that has a method to get the
    36  // charms management client.
    37  type CharmsCommandBase struct {
    38  	envcmd.EnvCommandBase
    39  }
    40  
    41  // NewCharmsClient returns a charms client for the root api endpoint
    42  // that the environment command returns.
    43  func (c *CharmsCommandBase) NewCharmsClient() (*charms.Client, error) {
    44  	root, err := c.NewAPIRoot()
    45  	if err != nil {
    46  		return nil, err
    47  	}
    48  	return charms.NewClient(root), nil
    49  }