Skip to content

Commit

Permalink
feat(cli): add option to dump the raw flux response from query (#19433)
Browse files Browse the repository at this point in the history
  • Loading branch information
glinton authored Aug 26, 2020
1 parent a5676f6 commit 80b8516
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
1. [19219](https://github.com/influxdata/influxdb/pull/19219): List buckets via the API now supports after (ID) parameter as an alternative to offset.
1. [19390](https://github.com/influxdata/influxdb/pull/19390): Record last success and failure run times in the Task
1. [19402](https://github.com/influxdata/influxdb/pull/19402): Inject Task's LatestSuccess Timestamp In Flux Extern
1. [19433](https://github.com/influxdata/influxdb/pull/19433): Add option to dump raw query results in CLI

### Bug Fixes

Expand Down
9 changes: 9 additions & 0 deletions cmd/influx/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
var queryFlags struct {
org organization
file string
raw bool
}

func cmdQuery(f *globalFlags, opts genericCLIOpts) *cobra.Command {
Expand All @@ -34,6 +35,7 @@ func cmdQuery(f *globalFlags, opts genericCLIOpts) *cobra.Command {
f.registerFlags(cmd)
queryFlags.org.register(cmd, true)
cmd.Flags().StringVarP(&queryFlags.file, "file", "f", "", "Path to Flux query file")
cmd.Flags().BoolVarP(&queryFlags.raw, "raw", "r", false, "Display raw query results")

return cmd
}
Expand Down Expand Up @@ -123,6 +125,11 @@ func fluxQueryF(cmd *cobra.Command, args []string) error {
return err
}

if queryFlags.raw {
io.Copy(os.Stdout, resp.Body)
return nil
}

dec := csv.NewMultiResultDecoder(csv.ResultDecoderConfig{})
results, err := dec.Decode(resp.Body)
if err != nil {
Expand All @@ -141,6 +148,8 @@ func fluxQueryF(cmd *cobra.Command, args []string) error {
return err
}
}
// It is safe and appropriate to call Release multiple times and must be
// called before checking the error on the next line.
results.Release()
return results.Err()
}
Expand Down

0 comments on commit 80b8516

Please sign in to comment.