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

Issue 6115048: Don't fight gnuflag; make use of its --help feature

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

Description

Don't fight gnuflag; make use of its --help feature When gnuflag encounters --help or -h, it calls its usage func and returns ErrHelp. To accommodate this behaviour, and get consistent output, we supply an empty Usage function and handle ErrHelp explicitly in Main. Because gnuflag is now used in such a way as to suppress all "automatic" output, there is no longer any reason to report errors in its style, and so errors reported on the command line are now prefixed with "error: " as originally intended; as a bonus, errors are now printed *after* help, and are therefore rather more obvious. https://code.launchpad.net/~fwereade/juju/go-fix-cmd-help/+merge/103448 Requires: https://code.launchpad.net/~fwereade/juju/go-fix-usage/+merge/103443 (do not edit description out of merge proposal)

Patch Set 1 #

Total comments: 2

Patch Set 2 : Don't fight gnuflag; make use of its --help feature #

Patch Set 3 : Don't fight gnuflag; make use of its --help feature #

Total comments: 4

Patch Set 4 : Don't fight gnuflag; make use of its --help feature #

Total comments: 5

Patch Set 5 : Don't fight gnuflag; make use of its --help feature #

Unified diffs Side-by-side diffs Delta from patch set Stats (+40 lines, -20 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 1 chunk +2 lines, -2 lines 0 comments Download
M cmd/context.go View 1 2 3 4 1 chunk +6 lines, -3 lines 0 comments Download
M cmd/context_test.go View 1 2 3 4 3 chunks +12 lines, -2 lines 0 comments Download
M cmd/juju/main_test.go View 1 2 3 4 3 chunks +17 lines, -12 lines 0 comments Download
M cmd/jujud/main_test.go View 1 2 3 4 1 chunk +1 line, -1 line 0 comments Download

Messages

Total messages: 9
fwereade
Please take a look.
12 years ago (2012-04-25 11:38:17 UTC) #1
rog
LGTM modulo the below. https://codereview.appspot.com/6115048/diff/1/cmd/context.go File cmd/context.go (right): https://codereview.appspot.com/6115048/diff/1/cmd/context.go#newcode75 cmd/context.go:75: printErr := func() { fmt.Fprintf(ctx.Stderr, ...
12 years ago (2012-04-25 11:56:03 UTC) #2
fwereade
Please take a look.
12 years ago (2012-04-25 11:57:35 UTC) #3
fwereade
Please take a look.
12 years ago (2012-04-25 13:44:07 UTC) #4
fwereade
https://codereview.appspot.com/6115048/diff/1/cmd/context.go File cmd/context.go (right): https://codereview.appspot.com/6115048/diff/1/cmd/context.go#newcode75 cmd/context.go:75: printErr := func() { fmt.Fprintf(ctx.Stderr, "ERROR: %v\n", err) } ...
12 years ago (2012-04-25 13:44:23 UTC) #5
niemeyer
I'm -1 on this CL. Feels like not only there's no benefit, but it is ...
12 years ago (2012-04-25 19:29:01 UTC) #6
fwereade
Please take a look. https://codereview.appspot.com/6115048/diff/8001/cmd/command.go File cmd/command.go (right): https://codereview.appspot.com/6115048/diff/8001/cmd/command.go#newcode29 cmd/command.go:29: // printHelp writes i's usage ...
12 years ago (2012-04-26 07:48:50 UTC) #7
niemeyer
Thanks, LGTM. Just a couple of minors to be considered please: https://codereview.appspot.com/6115048/diff/10001/cmd/command.go File cmd/command.go (right): ...
12 years ago (2012-04-26 13:13:59 UTC) #8
fwereade
12 years ago (2012-04-26 15:53:33 UTC) #9
*** Submitted:

Don't fight gnuflag; make use of its --help feature

When gnuflag encounters --help or -h, it calls its usage func and returns
ErrHelp. To accommodate this behaviour, and get consistent output, we supply
an empty Usage function and handle ErrHelp explicitly in Main.

Because gnuflag is now used in such a way as to suppress all "automatic"
output, there is no longer any reason to report errors in its style, and
so errors reported on the command line are now prefixed with "error: " as
originally intended; as a bonus, errors are now printed *after* help, and are
therefore rather more obvious.

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

https://codereview.appspot.com/6115048/diff/10001/cmd/command.go
File cmd/command.go (right):

https://codereview.appspot.com/6115048/diff/10001/cmd/command.go#newcode26
cmd/command.go:26: // help renders i's content, along with documentation for any
On 2012/04/26 13:13:59, niemeyer wrote:
> It feels like this is a nice bit for the public API of the package, but I'm
> happy to wait until we need it.

Coming as part of a followup anyway :).

https://codereview.appspot.com/6115048/diff/10001/cmd/context.go
File cmd/context.go (right):

https://codereview.appspot.com/6115048/diff/10001/cmd/context.go#newcode84
cmd/context.go:84: fmt.Fprintf(ctx.Stderr, "ERROR: %v\n", err)
On 2012/04/26 13:13:59, niemeyer wrote:
> I'd prefer to have that as s/ERROR/error/

Done, along with the reordering of help/error discussed on IRC.
Sign in to reply to this message.

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