github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/cmd/juju/application/trust.go (about)

     1  // Copyright 2018 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package application
     5  
     6  import (
     7  	"fmt"
     8  
     9  	"github.com/juju/cmd"
    10  	"github.com/juju/errors"
    11  	"github.com/juju/gnuflag"
    12  
    13  	"github.com/juju/juju/apiserver/facades/client/application"
    14  	jujucmd "github.com/juju/juju/cmd"
    15  	"github.com/juju/juju/cmd/modelcmd"
    16  )
    17  
    18  const (
    19  	trustSummary = `Sets the trust status of a deployed application to true.`
    20  	trustDetails = `Sets the trust configuration value to true.
    21  
    22  Examples:
    23      juju trust media-wiki
    24  
    25  See also:
    26      config
    27  `
    28  )
    29  
    30  type trustCommand struct {
    31  	configCommand
    32  	removeTrust bool
    33  }
    34  
    35  func NewTrustCommand() cmd.Command {
    36  	return modelcmd.Wrap(&trustCommand{})
    37  }
    38  
    39  // Info is part of the cmd.Command interface.
    40  func (c *trustCommand) Info() *cmd.Info {
    41  	return jujucmd.Info(&cmd.Info{
    42  		Name:    "trust",
    43  		Args:    "<application name>",
    44  		Purpose: trustSummary,
    45  		Doc:     trustDetails,
    46  	})
    47  }
    48  
    49  // SetFlags is part of the cmd.Command interface.
    50  func (c *trustCommand) SetFlags(f *gnuflag.FlagSet) {
    51  	c.ModelCommandBase.SetFlags(f)
    52  	f.BoolVar(&c.removeTrust, "remove", false, "Remove trusted access from a trusted application")
    53  }
    54  
    55  // Init is part of the cmd.Command interface.
    56  func (c *trustCommand) Init(args []string) error {
    57  	if len(args) == 0 {
    58  		return errors.New("no application name specified")
    59  	}
    60  	c.applicationName = args[0]
    61  	var trustOptionPair string
    62  	trustOptionPair = fmt.Sprintf("%s=%t", application.TrustConfigOptionName, !c.removeTrust)
    63  	return c.parseSet([]string{trustOptionPair})
    64  }