github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/worker/uniter/runner/jujuc/application-version-set.go (about)

     1  // Copyright 2016 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  	"github.com/juju/errors"
     9  
    10  	jujucmd "github.com/juju/juju/cmd"
    11  )
    12  
    13  type applicationVersionSetCommand struct {
    14  	cmd.CommandBase
    15  	ctx Context
    16  
    17  	version string
    18  }
    19  
    20  // NewApplicationVersionSetCommand creates an application-version-set command.
    21  func NewApplicationVersionSetCommand(ctx Context) (cmd.Command, error) {
    22  	cmd := &applicationVersionSetCommand{ctx: ctx}
    23  	return cmd, nil
    24  }
    25  
    26  // Info is part of the cmd.Command interface.
    27  func (c *applicationVersionSetCommand) Info() *cmd.Info {
    28  	doc := `
    29  application-version-set tells Juju which version of the application
    30  software is running. This could be a package version number or some
    31  other useful identifier, such as a Git hash, that indicates the
    32  version of the deployed software. (It shouldn't be confused with the
    33  charm revision.) The version set will be displayed in "juju status"
    34  output for the application.
    35  `
    36  	return jujucmd.Info(&cmd.Info{
    37  		Name:    "application-version-set",
    38  		Args:    "<new-version>",
    39  		Purpose: "specify which version of the application is deployed",
    40  		Doc:     doc,
    41  	})
    42  }
    43  
    44  // Init is part of the cmd.Command interface.
    45  func (c *applicationVersionSetCommand) Init(args []string) error {
    46  	if len(args) < 1 {
    47  		return errors.New("no version specified")
    48  	}
    49  	c.version = args[0]
    50  	return cmd.CheckEmpty(args[1:])
    51  }
    52  
    53  // Run is part of the cmd.Command interface.
    54  func (c *applicationVersionSetCommand) Run(ctx *cmd.Context) error {
    55  	return c.ctx.SetUnitWorkloadVersion(c.version)
    56  }