Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2930)

Issue 6123049: Moved printUsage to Info

Can't Edit
Can't Publish+Mail
Start Review
Created:
12 years ago by fwereade
Modified:
12 years ago
Reviewers:
mp+103443
Visibility:
Public.

Description

Moved printUsage to Info It became apparent that printUsage wasn't really using a Command, it was just using its Info so heavily as to imply it wanted to be a method on Info; and, having moved printUsage to Info, it became clear that options are the sole preserve of the gnuflag.FlagSet, and should not be mentioned in Info.Args (because to do so is to assert knowledge about the state of a shared resource, the FlagSet, without legitimately being able to do so). So, printUsage is now also responsible for inserting `[options]` into the usage line, in exactly the same way as it does the section actually describing those options (ie: it only does so if they exist). As a side-effect, SuperCommand `[options]` are placed before `<command> ...` in the usage line for the bare SuperCommand; this is IMO sensible because we're displaying the options that apply whatever command you select, and which actually *do* work in that position; ofc, when displaying help for a particular subcommand, we put the options after the command (and before its positional arguments). So we get: usage: juju [options] <command> ... ...and: usage: juju bootstrap [options] ...each of which accurately captures the possibilities in the appropriate situation. This branch also includes slightly heavier testing for SuperCommand's Info, and small tweaks to ensure consistent output of SuperCommand documentation as expected by those tests. https://code.launchpad.net/~fwereade/juju/go-fix-usage/+merge/103443 (do not edit description out of merge proposal)

Patch Set 1 #

Patch Set 2 : Moved printUsage to Info #

Total comments: 10

Patch Set 3 : Moved printUsage to Info #

Total comments: 10

Patch Set 4 : Moved printUsage to Info #

Total comments: 5

Patch Set 5 : Moved printUsage to Info #

Unified diffs Side-by-side diffs Delta from patch set Stats (+104 lines, -87 lines) Patch
A [revision details] View 1 2 3 4 1 chunk +2 lines, -0 lines 0 comments Download
M cmd/command.go View 1 2 3 2 chunks +32 lines, -8 lines 0 comments Download
M cmd/context.go View 1 2 3 3 chunks +7 lines, -31 lines 0 comments Download
M cmd/context_test.go View 2 chunks +2 lines, -2 lines 0 comments Download
M cmd/juju/bootstrap.go View 1 chunk +1 line, -5 lines 0 comments Download
M cmd/juju/main_test.go View 2 chunks +4 lines, -4 lines 0 comments Download
M cmd/jujud/agent.go View 1 chunk +1 line, -5 lines 0 comments Download
M cmd/jujud/initzk.go View 1 chunk +1 line, -5 lines 0 comments Download
M cmd/supercommand.go View 1 2 3 4 3 chunks +25 lines, -11 lines 0 comments Download
M cmd/supercommand_test.go View 1 2 3 4 3 chunks +29 lines, -16 lines 0 comments Download

Messages

Total messages: 10
fwereade
Please take a look.
12 years ago (2012-04-25 10:39:27 UTC) #1
fwereade
Please take a look.
12 years ago (2012-04-25 10:48:11 UTC) #2
rog
LGTM modulo doc suggestions and trivials. https://codereview.appspot.com/6123049/diff/3001/cmd/command.go File cmd/command.go (right): https://codereview.appspot.com/6123049/diff/3001/cmd/command.go#newcode31 cmd/command.go:31: // its output ...
12 years ago (2012-04-25 11:38:24 UTC) #3
fwereade
Please take a look. https://codereview.appspot.com/6123049/diff/3001/cmd/command.go File cmd/command.go (right): https://codereview.appspot.com/6123049/diff/3001/cmd/command.go#newcode31 cmd/command.go:31: // its output stream should ...
12 years ago (2012-04-25 11:53:07 UTC) #4
niemeyer
https://codereview.appspot.com/6123049/diff/7001/cmd/command.go File cmd/command.go (right): https://codereview.appspot.com/6123049/diff/7001/cmd/command.go#newcode14 cmd/command.go:14: // support code, and cannot be determined by examining ...
12 years ago (2012-04-25 19:17:04 UTC) #5
fwereade
Please take a look. https://codereview.appspot.com/6123049/diff/7001/cmd/command.go File cmd/command.go (right): https://codereview.appspot.com/6123049/diff/7001/cmd/command.go#newcode14 cmd/command.go:14: // support code, and cannot ...
12 years ago (2012-04-26 07:28:24 UTC) #6
niemeyer
LGTM. Just a suggestion: https://codereview.appspot.com/6123049/diff/12001/cmd/supercommand.go File cmd/supercommand.go (right): https://codereview.appspot.com/6123049/diff/12001/cmd/supercommand.go#newcode60 cmd/supercommand.go:60: sort.Strings(cmds) format := " %-" ...
12 years ago (2012-04-26 14:16:41 UTC) #7
rog
https://codereview.appspot.com/6123049/diff/12001/cmd/supercommand.go File cmd/supercommand.go (right): https://codereview.appspot.com/6123049/diff/12001/cmd/supercommand.go#newcode64 cmd/supercommand.go:64: cmds[i] = fmt.Sprintf(" %s %s", padded, purpose) On 2012/04/26 ...
12 years ago (2012-04-26 14:23:08 UTC) #8
niemeyer
> alternatively: > cmds[i] = fmt.Sprintf(" %-*s - %s", longest, padded, purpose) Hah, even nicer ...
12 years ago (2012-04-26 14:34:16 UTC) #9
fwereade
12 years ago (2012-04-26 15:06:47 UTC) #10
*** Submitted:

Moved printUsage to Info

It became apparent that printUsage wasn't really using a Command, it was
just using its Info so heavily as to imply it wanted to be a method on Info;
and, having moved printUsage to Info, it became clear that options are the
sole preserve of the gnuflag.FlagSet, and should not be mentioned in
Info.Args (because to do so is to assert knowledge about the state of a
shared resource, the FlagSet, without legitimately being able to do so). So,
printUsage is now also responsible for inserting `[options]` into the usage
line, in exactly the same way as it does the section actually describing
those options (ie: it only does so if they exist).

As a side-effect, SuperCommand `[options]` are placed before `<command> ...`
in the usage line for the bare SuperCommand; this is IMO sensible because
we're displaying the options that apply whatever command you select, and
which actually *do* work in that position; ofc, when displaying help for a
particular subcommand, we put the options after the command (and before its
positional arguments). So we get:

  usage: juju [options] <command> ...

...and:

  usage: juju bootstrap [options]

...each of which accurately captures the possibilities in the appropriate
situation.

This branch also includes slightly heavier testing for SuperCommand's Info,
and small tweaks to ensure consistent output of SuperCommand documentation
as expected by those tests.

R=rog, niemeyer
CC=
https://codereview.appspot.com/6123049

https://codereview.appspot.com/6123049/diff/12001/cmd/supercommand.go
File cmd/supercommand.go (right):

https://codereview.appspot.com/6123049/diff/12001/cmd/supercommand.go#newcode60
cmd/supercommand.go:60: sort.Strings(cmds)
On 2012/04/26 14:16:41, niemeyer wrote:
> format := "    %-" + strconv.Itoa(longest) + "s - %s"
> 
> (note the dash.. I think it'll look more clear with it)

Done.

https://codereview.appspot.com/6123049/diff/12001/cmd/supercommand.go#newcode64
cmd/supercommand.go:64: cmds[i] = fmt.Sprintf("    %s  %s", padded, purpose)
On 2012/04/26 14:16:41, niemeyer wrote:
> cmds[i] = fmt.Sprintf(format, name, purpose)

Done.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b