Skip to content

Commit d66e82b

Browse files
committed
cmd/modelcmd: provide flag to suppress browser login
This change makes logging in through a web browser the default, as that works even if the user hasn't logged in previously, but they can still get the current behaviour by using the -B flag. This requires all SetFlags implementations to call the SetFlags implementation of their embedded Base object (which is only good practice anyway) and we also simplify some of the resource command logic to use the shared APIContext implementation so that gets the benefit too, and remove some of the more unnecessary-seeming abstractions in that area.
1 parent 48b736e commit d66e82b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+162
-294
lines changed

cmd/juju/action/list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ For more information, see also the 'run-action' command, which executes actions.
4040

4141
// Set up the output.
4242
func (c *listCommand) SetFlags(f *gnuflag.FlagSet) {
43+
c.ActionCommandBase.SetFlags(f)
4344
c.out.AddFlags(f, "tabular", map[string]cmd.Formatter{
4445
"yaml": cmd.FormatYaml,
4546
"json": cmd.FormatJson,

cmd/juju/action/run.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ var ActionNameRule = regexp.MustCompile("^[a-z](?:[a-z-]*[a-z])?$")
111111

112112
// SetFlags offers an option for YAML output.
113113
func (c *runCommand) SetFlags(f *gnuflag.FlagSet) {
114+
c.ActionCommandBase.SetFlags(f)
114115
c.out.AddFlags(f, "yaml", output.DefaultFormatters)
115116
f.Var(&c.paramsYAML, "params", "Path to yaml-formatted params file")
116117
f.BoolVar(&c.parseStrings, "string-args", false, "Use raw string values of CLI args")

cmd/juju/action/showoutput.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ displayed. This is also the behavior when any negative time is given.
4242

4343
// Set up the output.
4444
func (c *showOutputCommand) SetFlags(f *gnuflag.FlagSet) {
45+
c.ActionCommandBase.SetFlags(f)
4546
c.out.AddFlags(f, "yaml", output.DefaultFormatters)
4647
f.StringVar(&c.wait, "wait", "-1s", "Wait for results")
4748
}

cmd/juju/action/status.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ If --name <name> is provided the search will be done by name rather than by ID.
3333

3434
// Set up the output.
3535
func (c *statusCommand) SetFlags(f *gnuflag.FlagSet) {
36+
c.ActionCommandBase.SetFlags(f)
3637
c.out.AddFlags(f, "yaml", output.DefaultFormatters)
3738
f.StringVar(&c.name, "name", "", "Action name")
3839
}

cmd/juju/application/constraints.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ func formatConstraints(writer io.Writer, value interface{}) error {
115115
}
116116

117117
func (c *serviceGetConstraintsCommand) SetFlags(f *gnuflag.FlagSet) {
118+
c.ModelCommandBase.SetFlags(f)
118119
c.out.AddFlags(f, "constraints", map[string]cmd.Formatter{
119120
"constraints": formatConstraints,
120121
"yaml": cmd.FormatYaml,

cmd/juju/application/get.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ func (c *getCommand) Info() *cmd.Info {
6262
}
6363

6464
func (c *getCommand) SetFlags(f *gnuflag.FlagSet) {
65+
c.ModelCommandBase.SetFlags(f)
6566
c.out.AddFlags(f, "yaml", output.DefaultFormatters)
6667
}
6768

cmd/juju/application/set.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func (c *setCommand) Info() *cmd.Info {
7777

7878
// SetFlags implements Command.SetFlags.
7979
func (c *setCommand) SetFlags(f *gnuflag.FlagSet) {
80+
c.ModelCommandBase.SetFlags(f)
8081
f.Var(&c.SettingsYAML, "config", "path to yaml-formatted application config")
8182
f.BoolVar(&c.SetDefault, "to-default", false, "set application option values to default")
8283
}

cmd/juju/application/upgradecharm.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ func (c *upgradeCharmCommand) Info() *cmd.Info {
122122
}
123123

124124
func (c *upgradeCharmCommand) SetFlags(f *gnuflag.FlagSet) {
125+
c.ModelCommandBase.SetFlags(f)
125126
f.BoolVar(&c.ForceUnits, "force-units", false, "Upgrade all units immediately, even if in error state")
126127
f.StringVar((*string)(&c.Channel), "channel", "", "Channel to use when getting the charm or bundle from the charm store")
127128
f.BoolVar(&c.ForceSeries, "force-series", false, "Upgrade even if series of deployed applications are not supported by the new charm")

cmd/juju/backups/backups.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func (c *CommandBase) NewAPIClient() (APIClient, error) {
5555

5656
// SetFlags implements Command.SetFlags.
5757
func (c *CommandBase) SetFlags(f *gnuflag.FlagSet) {
58+
c.ModelCommandBase.SetFlags(f)
5859
if c.Log != nil {
5960
c.Log.AddFlags(f)
6061
}

cmd/juju/block/block.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package block
66
import (
77
"github.com/juju/cmd"
88
"github.com/juju/errors"
9-
"github.com/juju/gnuflag"
109

1110
"github.com/juju/juju/cmd/modelcmd"
1211
)
@@ -42,11 +41,6 @@ func (c *BaseBlockCommand) internalRun(operation string) error {
4241
return client.SwitchBlockOn(TypeFromOperation(operation), c.desc)
4342
}
4443

45-
// SetFlags implements Command.SetFlags.
46-
func (c *BaseBlockCommand) SetFlags(f *gnuflag.FlagSet) {
47-
c.ModelCommandBase.SetFlags(f)
48-
}
49-
5044
// BlockClientAPI defines the client API methods that block command uses.
5145
type BlockClientAPI interface {
5246
Close() error

cmd/juju/block/unblock.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99

1010
"github.com/juju/cmd"
1111
"github.com/juju/errors"
12-
"github.com/juju/gnuflag"
1312

1413
"github.com/juju/juju/cmd/modelcmd"
1514
)
@@ -146,11 +145,6 @@ func (c *unblockCommand) Init(args []string) error {
146145
return c.assignValidOperation("unblock", args)
147146
}
148147

149-
// SetFlags implements Command.SetFlags.
150-
func (c *unblockCommand) SetFlags(f *gnuflag.FlagSet) {
151-
c.ModelCommandBase.SetFlags(f)
152-
}
153-
154148
// Run unblocks previously blocked commands.
155149
// Satisfying Command interface.
156150
func (c *unblockCommand) Run(_ *cmd.Context) error {

cmd/juju/charmcmd/charm.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ import (
77
"github.com/juju/cmd"
88
)
99

10+
var registeredSubCommands []cmd.Command
11+
12+
// RegisterSubCommand registers the given command as a "juju charm" subcommand.
13+
func RegisterSubCommand(c cmd.Command) {
14+
registeredSubCommands = append(registeredSubCommands, c)
15+
}
16+
1017
var charmDoc = `
1118
"juju charm" is the the juju CLI equivalent of the "charm" command used
1219
by charm authors, though only applicable functionality is mirrored.
@@ -31,14 +38,12 @@ func NewSuperCommand() *Command {
3138
},
3239
),
3340
}
34-
spec := newCharmstoreSpec()
3541

3642
// Sub-commands may be registered directly here, like so:
37-
//charmCmd.Register(newXXXCommand(spec))
43+
//charmCmd.Register(newXXXCommand())
3844

3945
// ...or externally via RegisterSubCommand().
40-
for _, newSubCommand := range registeredSubCommands {
41-
command := newSubCommand(spec)
46+
for _, command := range registeredSubCommands {
4247
charmCmd.Register(command)
4348
}
4449

cmd/juju/charmcmd/store.go

Lines changed: 0 additions & 55 deletions
This file was deleted.

cmd/juju/charmcmd/sub.go

Lines changed: 0 additions & 49 deletions
This file was deleted.

cmd/juju/cloud/add.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func (c *addCloudCommand) Info() *cmd.Info {
6464
}
6565

6666
func (c *addCloudCommand) SetFlags(f *gnuflag.FlagSet) {
67+
c.CommandBase.SetFlags(f)
6768
f.BoolVar(&c.Replace, "replace", false, "Overwrite any existing cloud information")
6869
}
6970

cmd/juju/cloud/addcredential.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ func (c *addCredentialCommand) Info() *cmd.Info {
9999
}
100100

101101
func (c *addCredentialCommand) SetFlags(f *gnuflag.FlagSet) {
102+
c.CommandBase.SetFlags(f)
102103
f.BoolVar(&c.Replace, "replace", false, "Overwrite existing credential information")
103104
f.StringVar(&c.CredentialsFile, "f", "", "The YAML file containing credentials to add")
104105
}

cmd/juju/cloud/list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func (c *listCloudsCommand) Info() *cmd.Info {
6161
}
6262

6363
func (c *listCloudsCommand) SetFlags(f *gnuflag.FlagSet) {
64+
c.CommandBase.SetFlags(f)
6465
c.out.AddFlags(f, "tabular", map[string]cmd.Formatter{
6566
"yaml": cmd.FormatYaml,
6667
"json": cmd.FormatJson,

cmd/juju/cloud/listcredentials.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ func (c *listCredentialsCommand) Info() *cmd.Info {
8484
}
8585

8686
func (c *listCredentialsCommand) SetFlags(f *gnuflag.FlagSet) {
87+
c.CommandBase.SetFlags(f)
8788
f.BoolVar(&c.showSecrets, "show-secrets", false, "Show secrets")
8889
c.out.AddFlags(f, "tabular", map[string]cmd.Formatter{
8990
"yaml": cmd.FormatYaml,

cmd/juju/cloud/show.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func NewShowCloudCommand() cmd.Command {
3838
}
3939

4040
func (c *showCloudCommand) SetFlags(f *gnuflag.FlagSet) {
41+
c.CommandBase.SetFlags(f)
4142
// We only support yaml for display purposes.
4243
c.out.AddFlags(f, "yaml", map[string]cmd.Formatter{
4344
"yaml": cmd.FormatYaml,

cmd/juju/commands/bootstrap.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,6 @@ type bootstrapCommand struct {
144144
Region string
145145
noGUI bool
146146
interactive bool
147-
148-
flagset *gnuflag.FlagSet
149147
}
150148

151149
func (c *bootstrapCommand) Info() *cmd.Info {
@@ -158,9 +156,7 @@ func (c *bootstrapCommand) Info() *cmd.Info {
158156
}
159157

160158
func (c *bootstrapCommand) SetFlags(f *gnuflag.FlagSet) {
161-
// we need to store this so that later we can easily check how many flags
162-
// have been set (for interactive mode).
163-
c.flagset = f
159+
c.ModelCommandBase.SetFlags(f)
164160
f.Var(constraints.ConstraintsValue{Target: &c.Constraints}, "constraints", "Set model constraints")
165161
f.Var(constraints.ConstraintsValue{Target: &c.BootstrapConstraints}, "bootstrap-constraints", "Specify bootstrap machine constraints")
166162
f.StringVar(&c.BootstrapSeries, "bootstrap-series", "", "Specify the series of the bootstrap machine")

cmd/juju/commands/debuglog.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ type debugLogCommand struct {
133133
}
134134

135135
func (c *debugLogCommand) SetFlags(f *gnuflag.FlagSet) {
136+
c.ModelCommandBase.SetFlags(f)
136137
f.Var(cmd.NewAppendStringsValue(&c.params.IncludeEntity), "i", "Only show log messages for these entities")
137138
f.Var(cmd.NewAppendStringsValue(&c.params.IncludeEntity), "include", "Only show log messages for these entities")
138139
f.Var(cmd.NewAppendStringsValue(&c.params.ExcludeEntity), "x", "Do not show log messages for these entities")

cmd/juju/commands/enableha.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ func (c *enableHACommand) Info() *cmd.Info {
144144
}
145145

146146
func (c *enableHACommand) SetFlags(f *gnuflag.FlagSet) {
147+
c.ModelCommandBase.SetFlags(f)
147148
f.IntVar(&c.NumControllers, "n", 0, "Number of controllers to make available")
148149
f.StringVar(&c.PlacementSpec, "to", "", "The machine(s) to become controllers, bypasses constraints")
149150
f.Var(constraints.ConstraintsValue{&c.Constraints}, "constraints", "Additional machine constraints")

cmd/juju/commands/list_sshkeys.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ func (c *listKeysCommand) Info() *cmd.Info {
5757

5858
// SetFlags implements Command.SetFlags.
5959
func (c *listKeysCommand) SetFlags(f *gnuflag.FlagSet) {
60+
c.SSHKeysBase.SetFlags(f)
6061
f.BoolVar(&c.showFullKey, "full", false, "Show full key instead of just the fingerprint")
6162
}
6263

cmd/juju/commands/resolved.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func (c *resolvedCommand) Info() *cmd.Info {
3333
}
3434

3535
func (c *resolvedCommand) SetFlags(f *gnuflag.FlagSet) {
36+
c.ModelCommandBase.SetFlags(f)
3637
f.BoolVar(&c.Retry, "r", false, "Re-execute failed hooks")
3738
f.BoolVar(&c.Retry, "retry", false, "")
3839
}

cmd/juju/commands/run.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ func (c *runCommand) Info() *cmd.Info {
7878
}
7979

8080
func (c *runCommand) SetFlags(f *gnuflag.FlagSet) {
81+
c.ModelCommandBase.SetFlags(f)
8182
c.out.AddFlags(f, "default", map[string]cmd.Formatter{
8283
"yaml": cmd.FormatYaml,
8384
"json": cmd.FormatJson,

cmd/juju/commands/ssh_common.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ var sshHostFromTargetAttemptStrategy attemptStarter = attemptStrategy{
8888
}
8989

9090
func (c *SSHCommon) SetFlags(f *gnuflag.FlagSet) {
91+
c.ModelCommandBase.SetFlags(f)
9192
f.BoolVar(&c.proxy, "proxy", false, "Proxy through the API server")
9293
f.BoolVar(&c.pty, "pty", true, "Enable pseudo-tty allocation")
9394
f.BoolVar(&c.noHostKeyChecks, "no-host-key-checks", false, "Skip host key checking (INSECURE)")

cmd/juju/commands/synctools.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func (c *syncToolsCommand) Info() *cmd.Info {
7979
}
8080

8181
func (c *syncToolsCommand) SetFlags(f *gnuflag.FlagSet) {
82+
c.ModelCommandBase.SetFlags(f)
8283
f.BoolVar(&c.allVersions, "all", false, "Copy all versions, not just the latest")
8384
f.StringVar(&c.versionStr, "version", "", "Copy a specific major[.minor] version")
8485
f.BoolVar(&c.dryRun, "dry-run", false, "Don't copy, just print what would be copied")

cmd/juju/commands/upgradejuju.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ func (c *upgradeJujuCommand) Info() *cmd.Info {
9393
}
9494

9595
func (c *upgradeJujuCommand) SetFlags(f *gnuflag.FlagSet) {
96+
c.ModelCommandBase.SetFlags(f)
9697
f.StringVar(&c.vers, "version", "", "Upgrade to specific version")
9798
f.BoolVar(&c.BuildAgent, "build-agent", false, "Build a local version of the agent binary; for development use only")
9899
f.BoolVar(&c.DryRun, "dry-run", false, "Don't change anything, just report what would be changed")

cmd/juju/controller/addmodel.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ func (c *addModelCommand) Info() *cmd.Info {
9797
}
9898

9999
func (c *addModelCommand) SetFlags(f *gnuflag.FlagSet) {
100+
c.ControllerCommandBase.SetFlags(f)
100101
f.StringVar(&c.Owner, "owner", "", "The owner of the new model if not the current user")
101102
f.StringVar(&c.CredentialName, "credential", "", "Credential used to add the model")
102103
f.Var(&c.Config, "config", "Path to YAML model configuration file or individual options (--config config.yaml [--config key=value ...])")

cmd/juju/controller/destroy.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ func (c *destroyCommand) Info() *cmd.Info {
103103

104104
// SetFlags implements Command.SetFlags.
105105
func (c *destroyCommand) SetFlags(f *gnuflag.FlagSet) {
106-
f.BoolVar(&c.destroyModels, "destroy-all-models", false, "Destroy all hosted models in the controller")
107106
c.destroyCommandBase.SetFlags(f)
107+
f.BoolVar(&c.destroyModels, "destroy-all-models", false, "Destroy all hosted models in the controller")
108108
}
109109

110110
// Run implements Command.Run
@@ -311,6 +311,7 @@ func (c *destroyCommandBase) getControllerAPI() (destroyControllerAPI, error) {
311311

312312
// SetFlags implements Command.SetFlags.
313313
func (c *destroyCommandBase) SetFlags(f *gnuflag.FlagSet) {
314+
c.ControllerCommandBase.SetFlags(f)
314315
f.BoolVar(&c.assumeYes, "y", false, "Do not ask for confirmation")
315316
f.BoolVar(&c.assumeYes, "yes", false, "")
316317
}

0 commit comments

Comments
 (0)