Skip to content

Commit

Permalink
Streaming CLI Output
Browse files Browse the repository at this point in the history
This patch adds a new feature to REX-Ray's Volume CLI so that streaming
output is supported. By setting the environment variable
"REXRAY_CLI_TABWRITER_AUTOFLUSH" to a truthy value, the CLI will emit
results as they are produced rather than waiting until all results are
available. For example:

    $ REXRAY_CLI_TABWRITER_AUTOFLUSH=true \
      rexray volume create build1 build2 build3 --size 16

The above command will create three volumes named "build1", "build2",
and "build3" with a size of 16GB. With the above environment variable
set, however, the CLI will emit the volumes as they're created instead
of waiting until all three have been processed.

If an error occurs when processing multiple items, the error is written
to the console in the middle of the normal, tabular output. However, the
error is written to the STDERR file descriptor instead of STDOUT,
meaning it is very simple to pay attention to only the successful
results if so desired.

The streaming output is also supported for the "json" and "jsonp"
formats.

There is one caveat to using the streaming output option -- there is no
longer a guarantee that tabular data will be properly aligned. While the
data will still be separated by tabs, the data must normally be buffered
until it is all available to know how to properly produce the formatted
table. Streaming the data means padding can only be generated based upon
the current and previous entries, but not possible, future ones. For
example:

    ID     Name      Status     Size  Path
    vol-0  builds-0  available  10240
    vol-1  builds-1  available  10240
    error querying volume vol-2
    vol-3  builds-3-abcdefghik  available  10240
    vol-4  builds-4  available  10240

The above output demonstrates two things: 1) an error emitted to STDERR
in the middle of the tabular data that has been written to STDOUT and 2)
the entry for "vol-3" is not properly aligned due to the fact that the
tabular formatting was calculated well in advance of the "vol-3" data
being taken into consideration.
  • Loading branch information
akutz committed Oct 24, 2016
1 parent 429cfdf commit cec92e9
Show file tree
Hide file tree
Showing 7 changed files with 622 additions and 447 deletions.
8 changes: 0 additions & 8 deletions cli/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ type CLI struct {
dryRun bool
continueOnError bool
outputFormat string
outputTemplate string
outputTemplateTabs bool
fg bool
fork bool
force bool
Expand Down Expand Up @@ -280,12 +278,6 @@ func (c *CLI) addOutputFormatFlag(fs *pflag.FlagSet) {
fs.StringVarP(
&c.outputFormat, "format", "f", "tmpl",
"The output format (tmpl, json, jsonp)")
fs.StringVarP(
&c.outputTemplate, "template", "", "",
"The Go template to use when --format is set to 'tmpl'")
fs.BoolVarP(
&c.outputTemplateTabs, "templateTabs", "", true,
"Set to true to use a Go tab writer with the output template")
}
func (c *CLI) addQuietFlag(fs *pflag.FlagSet) {
fs.BoolVarP(&c.quiet, "quiet", "q", false, "Suppress table headers")
Expand Down
Loading

0 comments on commit cec92e9

Please sign in to comment.