Skip to content

Commit cac5bc1

Browse files
committed
User facing commands consistent wih "options" vs 'flags'.
1 parent 220b045 commit cac5bc1

File tree

8 files changed

+26
-12
lines changed

8 files changed

+26
-12
lines changed

Gopkg.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@
287287

288288
[[constraint]]
289289
name = "github.com/juju/cmd"
290-
revision = "e74f39857ca013cf63947ba2843806f7afdd380d"
290+
revision = "fd568e4a4120f7d5a417252d701daff61a6322b4"
291291

292292
[[constraint]]
293293
name = "github.com/juju/collections"

cmd/juju/application/deploy_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ func (s *DeploySuite) TestDeployLocalWithTerms(c *gc.C) {
797797

798798
func (s *DeploySuite) TestDeployFlags(c *gc.C) {
799799
command := DeployCommand{}
800-
flagSet := gnuflag.NewFlagSet(command.Info().Name, gnuflag.ContinueOnError)
800+
flagSet := gnuflag.NewFlagSetWithFlagKnownAs(command.Info().Name, gnuflag.ContinueOnError, "option")
801801
command.SetFlags(flagSet)
802802
c.Assert(command.flagSet, jc.DeepEquals, flagSet)
803803
// Add to the slice below if a new flag is introduced which is valid for

cmd/juju/commands/helptool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (c *helpToolCommand) Run(ctx *cmd.Context) error {
130130
return err
131131
}
132132
info := c.Info()
133-
f := gnuflag.NewFlagSet(info.Name, gnuflag.ContinueOnError)
133+
f := gnuflag.NewFlagSetWithFlagKnownAs(info.Name, gnuflag.ContinueOnError, cmd.FlagAlias(c, "option"))
134134
c.SetFlags(f)
135135
ctx.Stdout.Write(info.Help(f))
136136
}

cmd/juju/commands/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ func NewJujuCommand(ctx *cmd.Context) cmd.Command {
259259
Doc: jujuDoc,
260260
MissingCallback: RunPlugin,
261261
UserAliasesFilename: osenv.JujuXDGDataHomePath("aliases"),
262+
FlagKnownAs: "option",
262263
})
263264
jcmd.AddHelpTopic("basics", "Basic Help Summary", usageHelp)
264265
registerCommands(jcmd, ctx)

cmd/juju/commands/main_test.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
package commands
55

66
import (
7+
"bytes"
78
"fmt"
9+
"github.com/juju/gnuflag"
810
"io/ioutil"
911
"os"
1012
"path/filepath"
@@ -40,15 +42,25 @@ type MainSuite struct {
4042

4143
var _ = gc.Suite(&MainSuite{})
4244

45+
func helpText(command cmd.Command, name string) string {
46+
buff := &bytes.Buffer{}
47+
info := command.Info()
48+
info.Name = name
49+
f := gnuflag.NewFlagSetWithFlagKnownAs(info.Name, gnuflag.ContinueOnError, cmd.FlagAlias(command, "option"))
50+
command.SetFlags(f)
51+
buff.Write(info.Help(f))
52+
return buff.String()
53+
}
54+
4355
func deployHelpText() string {
44-
return cmdtesting.HelpText(application.NewDeployCommand(), "juju deploy")
56+
return helpText(application.NewDeployCommand(), "juju deploy")
4557
}
4658
func configHelpText() string {
47-
return cmdtesting.HelpText(application.NewConfigCommand(), "juju config")
59+
return helpText(application.NewConfigCommand(), "juju config")
4860
}
4961

5062
func syncToolsHelpText() string {
51-
return cmdtesting.HelpText(newSyncToolsCommand(), "juju sync-agent-binaries")
63+
return helpText(newSyncToolsCommand(), "juju sync-agent-binaries")
5264
}
5365

5466
func (s *MainSuite) TestRunMain(c *gc.C) {
@@ -104,17 +116,17 @@ func (s *MainSuite) TestRunMain(c *gc.C) {
104116
summary: "unknown option before command",
105117
args: []string{"--cheese", "bootstrap"},
106118
code: 2,
107-
out: "ERROR flag provided but not defined: --cheese\n",
119+
out: "ERROR option provided but not defined: --cheese\n",
108120
}, {
109121
summary: "unknown option after command",
110122
args: []string{"bootstrap", "--cheese"},
111123
code: 2,
112-
out: "ERROR flag provided but not defined: --cheese\n",
124+
out: "ERROR option provided but not defined: --cheese\n",
113125
}, {
114126
summary: "known option, but specified before command",
115127
args: []string{"--model", "blah", "bootstrap"},
116128
code: 2,
117-
out: "ERROR flag provided but not defined: --model\n",
129+
out: "ERROR option provided but not defined: --model\n",
118130
}, {
119131
summary: "juju sync-agent-binaries registered properly",
120132
args: []string{"sync-agent-binaries", "--help"},

cmd/juju/commands/plugin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func RunPlugin(ctx *cmd.Context, subcommand string, args []string) error {
5454
// We process common flags supported by Juju commands.
5555
// To do this, we extract only those supported flags from the
5656
// argument list to avoid confusing flags.Parse().
57-
flags := gnuflag.NewFlagSet(cmdName, gnuflag.ContinueOnError)
57+
flags := gnuflag.NewFlagSetWithFlagKnownAs(cmdName, gnuflag.ContinueOnError, "option")
5858
flags.SetOutput(ioutil.Discard)
5959
plugin.SetFlags(flags)
6060
jujuArgs := extractJujuArgs(args)

cmd/supercommand.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func NewSuperCommand(p cmd.SuperCommandParams) *cmd.SuperCommand {
4949
// tests to assert that this string value is correct.
5050
p.Version = current.String()
5151
p.NotifyRun = runNotifier
52+
p.FlagKnownAs = "option"
5253
return cmd.NewSuperCommand(p)
5354
}
5455

0 commit comments

Comments
 (0)