DescriptionAdd 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 #
MessagesTotal messages: 13
|