From f1926bda5613edd606d0357695b9a67d20926781 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 29 Nov 2017 15:20:19 -0500 Subject: [PATCH] Bug 19716: Add option to send header line for CSV output Currently, if outputting a CSV file using runreport.pl, you need to look at the report used to know what each column means. It would be nice if we could include column headers. Test Plan: 1) Apply this patch 2) Try using runreport.pl with --format csv --csv-header Signed-off-by: David Bourgault Signed-off-by: Julian Maurice Signed-off-by: Jonathan Druart --- misc/cronjobs/runreport.pl | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/misc/cronjobs/runreport.pl b/misc/cronjobs/runreport.pl index 1648f4d72a..cb10125938 100755 --- a/misc/cronjobs/runreport.pl +++ b/misc/cronjobs/runreport.pl @@ -66,6 +66,7 @@ runreport.pl [ -h | -m ] [ -v ] reportID [ reportID ... ] --from=s e-mail address to send report from --subject=s subject for the e-mail --store-results store the result of the report + --csv-header add column names as first line of csv output Arguments: @@ -175,6 +176,7 @@ my $subject = ""; my $separator = ','; my $quote = '"'; my $store_results = 0; +my $csv_header = 0; my $username = undef; my $password = undef; @@ -194,6 +196,7 @@ GetOptions( 'password:s' => \$password, 'method:s' => \$method, 'store-results' => \$store_results, + 'csv-header' => \$csv_header, ) or pod2usage(2); pod2usage( -verbose => 2 ) if ($man); @@ -273,6 +276,14 @@ foreach my $report_id (@ARGV) { quote_char => $quote, sep_char => $separator, }); + + if ( $csv_header ) { + my $fields = $sth->{NAME}; + $csv->combine( @$fields ); + $message .= $csv->string() . "\n"; + push @rows_to_store, [@$fields] if $store_results; + } + while (my $line = $sth->fetchrow_arrayref) { $csv->combine(@$line); $message .= $csv->string() . "\n"; -- 2.39.5