1
// Copyright 2016 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
10
"github.com/juju/errors"
11
"launchpad.net/gnuflag"
13
jujucmd "github.com/juju/juju/cmd"
14
"github.com/juju/juju/cmd/modelcmd"
15
"github.com/juju/juju/jujuclient"
18
// NewUnregisterCommand returns a command to allow the user to unregister a controller.
19
func NewUnregisterCommand(store jujuclient.ClientStore) cmd.Command {
21
panic("valid store must be specified")
23
cmd := &unregisterCommand{store: store}
24
return modelcmd.WrapBase(cmd)
27
// unregisterCommand removes a Juju controller from the local store.
28
type unregisterCommand struct {
29
modelcmd.JujuCommandBase
32
store jujuclient.ClientStore
35
var usageUnregisterDetails = `
36
Removes local connection information for the specified controller.
37
This command does not destroy the controller. In order to regain
38
access to an unregistered controller, it will need to be added
39
again using the juju register command.
43
juju unregister my-controller
48
// Info implements Command.Info
49
// `unregister` may seem generic as a command, but aligns with `register`.
50
func (c *unregisterCommand) Info() *cmd.Info {
53
Args: "<controller name>",
54
Purpose: "Unregisters a Juju controller",
55
Doc: usageUnregisterDetails,
59
// SetFlags implements Command.SetFlags.
60
func (c *unregisterCommand) SetFlags(f *gnuflag.FlagSet) {
61
f.BoolVar(&c.assumeYes, "y", false, "Do not prompt for confirmation")
62
f.BoolVar(&c.assumeYes, "yes", false, "")
65
// Init implements Command.Init.
66
func (c *unregisterCommand) Init(args []string) error {
68
return errors.New("controller name must be specified")
70
c.controllerName, args = args[0], args[1:]
72
if err := jujuclient.ValidateControllerName(c.controllerName); err != nil {
76
if err := cmd.CheckEmpty(args); err != nil {
83
This command will remove connection information for controller %q.
84
Doing so will prevent you from accessing this controller until
85
you register it again.
89
func (c *unregisterCommand) Run(ctx *cmd.Context) error {
91
_, err := c.store.ControllerByName(c.controllerName)
93
return errors.Trace(err)
97
fmt.Fprintf(ctx.Stdout, unregisterMsg, c.controllerName)
99
if err := jujucmd.UserConfirmYes(ctx); err != nil {
100
return errors.Annotate(err, "unregistering controller")
104
return (c.store.RemoveController(c.controllerName))