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

Issue 5758050: Add cmd.Context type to enable output capture and environment control

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

Description

Add cmd.Context type to enable output capture and environment control In order to run a Command inside another process, the host process needs to know the client's working directory (for relative file paths), and it needs separate output streams (so that it goes where it's intended). The only impact on existing Commands is that their Run method now expects a *cmd.Context; the only command that's materially affected is SuperCommand, which becomes slightly simpler (because logging setup is now the responsibility of the Context; SuperCommand just parses the args and hands them over). FlagSets are now always constructed with ContinueOnError, and with configurable output; this unifies error handling and usage printing (there's now only one code path for each), and allows us to correctly print usage for commands that don't have any sensible options (eg open-port). As a side-effect, it's much simpler to test command-line parsing for arbitrary commands, because errors no longer cause os.Exit to be called. For clarity's sake, pre-existing tests have been left untouched; expect a followup branch that tidies up main and main_test in juju and jujud. PrintUsage and NewFlagSet are now private (in addition to expecting an io.Writer for output), because they weren't used externally in the first place, and in practice were just dirtying up the interface. https://code.launchpad.net/~fwereade/juju/go-add-cmd-context/+merge/96131 (do not edit description out of merge proposal)

Patch Set 1 #

Patch Set 2 : Add cmd.Context type to enable output capture and environment control #

Patch Set 3 : Add cmd.Context type to enable output capture and environment control #

Patch Set 4 : Add cmd.Context type to enable output capture and environment control #

Total comments: 21

Patch Set 5 : Add cmd.Context type to enable output capture and environment control #

Total comments: 1

Patch Set 6 : Add cmd.Context type to enable output capture and environment control #

Patch Set 7 : Add cmd.Context type to enable output capture and environment control #

Patch Set 8 : Add cmd.Context type to enable output capture and environment control #

Patch Set 9 : Add cmd.Context type to enable output capture and environment control #

Unified diffs Side-by-side diffs Delta from patch set Stats (+287 lines, -82 lines) Patch
A [revision details] View 1 2 3 4 5 6 1 chunk +2 lines, -0 lines 0 comments Download
M cmd/command.go View 1 2 3 4 4 chunks +36 lines, -34 lines 0 comments Download
A cmd/context.go View 1 2 3 4 1 chunk +82 lines, -0 lines 0 comments Download
A cmd/context_test.go View 1 2 3 4 1 chunk +141 lines, -0 lines 0 comments Download
M cmd/juju/bootstrap.go View 1 2 3 4 1 chunk +1 line, -1 line 0 comments Download
M cmd/juju/main.go View 1 2 3 4 1 chunk +3 lines, -3 lines 0 comments Download
M cmd/jujud/initzk.go View 1 2 3 4 1 chunk +1 line, -1 line 0 comments Download
M cmd/jujud/machine.go View 1 2 3 4 2 chunks +2 lines, -1 line 0 comments Download
M cmd/jujud/main.go View 1 2 3 4 1 chunk +6 lines, -6 lines 0 comments Download
M cmd/jujud/provisioning.go View 1 2 3 4 2 chunks +5 lines, -2 lines 0 comments Download
M cmd/jujud/unit.go View 1 2 3 4 2 chunks +2 lines, -1 line 0 comments Download
M cmd/supercommand.go View 1 2 3 4 5 3 chunks +4 lines, -30 lines 0 comments Download
M cmd/supercommand_test.go View 1 2 3 chunks +2 lines, -3 lines 0 comments Download

Messages

Total messages: 13
fwereade
Please take a look.
12 years, 2 months ago (2012-03-06 14:41:58 UTC) #1
fwereade
Please take a look.
12 years, 1 month ago (2012-03-09 09:37:09 UTC) #2
fwereade
Please take a look.
12 years, 1 month ago (2012-03-13 09:31:39 UTC) #3
fwereade
Please take a look.
12 years, 1 month ago (2012-03-13 09:32:11 UTC) #4
niemeyer
That one looks pretty nice, thanks William. https://codereview.appspot.com/5758050/diff/8001/cmd/command.go File cmd/command.go (right): https://codereview.appspot.com/5758050/diff/8001/cmd/command.go#newcode67 cmd/command.go:67: // options ...
12 years, 1 month ago (2012-03-16 23:23:54 UTC) #5
fwereade
https://codereview.appspot.com/5758050/diff/8001/cmd/command.go File cmd/command.go (right): https://codereview.appspot.com/5758050/diff/8001/cmd/command.go#newcode67 cmd/command.go:67: // options directs PrintDefaults on c's FlagSet to a ...
12 years, 1 month ago (2012-03-17 01:01:23 UTC) #6
fwereade
Please take a look.
12 years, 1 month ago (2012-03-17 01:04:10 UTC) #7
rog
LGTM https://codereview.appspot.com/5758050/diff/13001/cmd/juju/bootstrap.go File cmd/juju/bootstrap.go (right): https://codereview.appspot.com/5758050/diff/13001/cmd/juju/bootstrap.go#newcode39 cmd/juju/bootstrap.go:39: func (c *BootstrapCommand) Run(_ *cmd.Context) error { you ...
12 years, 1 month ago (2012-03-22 11:09:08 UTC) #8
fwereade
Please take a look.
12 years ago (2012-04-19 13:16:39 UTC) #9
fwereade
Please take a look.
12 years ago (2012-04-23 08:42:23 UTC) #10
fwereade
Please take a look.
12 years ago (2012-04-23 09:00:41 UTC) #11
niemeyer
LGTM. Thanks! https://codereview.appspot.com/5758050/diff/8001/cmd/context.go File cmd/context.go (right): https://codereview.appspot.com/5758050/diff/8001/cmd/context.go#newcode13 cmd/context.go:13: // to allow use of the cmd ...
12 years ago (2012-04-23 23:39:14 UTC) #12
fwereade
12 years ago (2012-04-24 07:30:31 UTC) #13
*** Submitted:

Add cmd.Context type to enable output capture and environment control

In order to run a Command inside another process, the host process needs to
know the client's working directory (for relative file paths), and it needs
separate output streams (so that it goes where it's intended).

The only impact on existing Commands is that their Run method now expects a
*cmd.Context; the only command that's materially affected is SuperCommand,
which becomes slightly simpler (because logging setup is now the
responsibility of the Context; SuperCommand just parses the args and hands
them over).

FlagSets are now always constructed with ContinueOnError, and with
configurable output; this unifies error handling and usage printing (there's
now only one code path for each), and allows us to correctly print usage for
commands that don't have any sensible options (eg open-port). As a
side-effect, it's much simpler to test command-line parsing for arbitrary
commands, because errors no longer cause os.Exit to be called. For clarity's
sake, pre-existing tests have been left untouched; expect a followup branch
that tidies up main and main_test in juju and jujud.

PrintUsage and NewFlagSet are now private (in addition to expecting an
io.Writer for output), because they weren't used externally in the first
place, and in practice were just dirtying up the interface.

R=niemeyer, rog
CC=
https://codereview.appspot.com/5758050
Sign in to reply to this message.

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