1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
10
"github.com/juju/errors"
11
"github.com/juju/names"
13
"github.com/juju/juju/cmd/juju/block"
14
"github.com/juju/juju/cmd/modelcmd"
17
const shareEnvHelpDoc = `
18
Share the current model with another user.
22
Give local user "joe" access to the current model
24
juju share-model user1 user2 user3@ubuntuone
25
Give two local users and one remote user access to the current model
27
juju share-model sam --model myenv
28
Give local user "sam" access to the model named "myenv"
31
func NewShareCommand() cmd.Command {
32
return modelcmd.Wrap(&shareCommand{})
35
// shareCommand represents the command to share an environment with a user(s).
36
type shareCommand struct {
37
modelcmd.ModelCommandBase
39
api ShareEnvironmentAPI
41
// Users to share the environment with.
45
// Info implements Command.Info.
46
func (c *shareCommand) Info() *cmd.Info {
50
Purpose: "share the current model with another user",
51
Doc: strings.TrimSpace(shareEnvHelpDoc),
55
func (c *shareCommand) Init(args []string) (err error) {
57
return errors.New("no users specified")
60
for _, arg := range args {
61
if !names.IsValidUser(arg) {
62
return errors.Errorf("invalid username: %q", arg)
64
c.Users = append(c.Users, names.NewUserTag(arg))
70
func (c *shareCommand) getAPI() (ShareEnvironmentAPI, error) {
74
return c.NewAPIClient()
77
// ShareEnvironmentAPI defines the API functions used by the environment share command.
78
type ShareEnvironmentAPI interface {
80
ShareModel(...names.UserTag) error
83
func (c *shareCommand) Run(ctx *cmd.Context) error {
84
client, err := c.getAPI()
90
return block.ProcessBlockedError(client.ShareModel(c.Users...), block.BlockChange)