@@ -49,14 +49,18 @@ func DownloadQueryPatternsCmd(ch *cmdutil.Helper) *cobra.Command {
4949 RunE : func (cmd * cobra.Command , args []string ) error {
5050 ctx := cmd .Context ()
5151 database , branch := args [0 ], args [1 ]
52+ toStdout := flags .output == "-"
5253
5354 client , err := ch .Client ()
5455 if err != nil {
5556 return err
5657 }
5758
58- end := ch .Printer .PrintProgress (fmt .Sprintf ("Generating query patterns report for %s in %s..." ,
59- printer .BoldBlue (branch ), printer .BoldBlue (database )))
59+ end := func () {}
60+ if ! toStdout {
61+ end = ch .Printer .PrintProgress (fmt .Sprintf ("Generating query patterns report for %s in %s..." ,
62+ printer .BoldBlue (branch ), printer .BoldBlue (database )))
63+ }
6064 defer end ()
6165
6266 report , err := client .QueryPatterns .CreateReport (ctx , & ps.CreateQueryPatternsReportRequest {
@@ -111,6 +115,13 @@ func DownloadQueryPatternsCmd(ch *cmdutil.Helper) *cobra.Command {
111115 }
112116 defer body .Close ()
113117
118+ if toStdout {
119+ if _ , err := io .Copy (cmd .OutOrStdout (), body ); err != nil {
120+ return fmt .Errorf ("writing query patterns report to stdout: %w" , err )
121+ }
122+ return nil
123+ }
124+
114125 f , err := os .Create (path )
115126 if err != nil {
116127 return fmt .Errorf ("creating file %s: %w" , path , err )
@@ -140,7 +151,7 @@ func DownloadQueryPatternsCmd(ch *cmdutil.Helper) *cobra.Command {
140151 }
141152
142153 cmd .Flags ().StringVar (& flags .output , "output" , "" ,
143- "Output file for the query patterns report. Defaults to the current directory as query-patterns-<organization>-<database>-<branch>-<timestamp>.csv." )
154+ "Output file name, or - to write to stdout. Defaults to query-patterns-<organization>-<database>-<branch>-<timestamp>.csv." )
144155
145156 return cmd
146157}
0 commit comments