From 51d00fcbe54dd30cc56755eefa0f0fb6f3b83e2b Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Sat, 13 Jun 2020 16:31:38 +0800 Subject: [PATCH] [gnucash-cli] --report show/list outputs to stdout and their error messages output to stderr --- gnucash/gnucash-commands.cpp | 8 +++++--- gnucash/report/report-core.scm | 22 +++++++++++----------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/gnucash/gnucash-commands.cpp b/gnucash/gnucash-commands.cpp index 9627db0f0f..5ee2669d85 100644 --- a/gnucash/gnucash-commands.cpp +++ b/gnucash/gnucash-commands.cpp @@ -214,8 +214,9 @@ scm_report_show (void *data, scm_c_use_module ("gnucash reports"); gnc_report_init (); - scm_call_1 (scm_c_eval_string ("gnc:cmdline-report-show"), - scm_from_utf8_string (args->show_report.c_str())); + scm_call_2 (scm_c_eval_string ("gnc:cmdline-report-show"), + scm_from_utf8_string (args->show_report.c_str ()), + scm_current_output_port ()); gnc_shutdown (0); return; } @@ -230,7 +231,8 @@ scm_report_list ([[maybe_unused]] void *data, scm_c_use_module ("gnucash reports"); gnc_report_init (); - scm_call_0 (scm_c_eval_string ("gnc:cmdline-report-list")); + scm_call_1 (scm_c_eval_string ("gnc:cmdline-report-list"), + scm_current_output_port ()); gnc_shutdown (0); return; } diff --git a/gnucash/report/report-core.scm b/gnucash/report/report-core.scm index 804b856252..3dce45f056 100644 --- a/gnucash/report/report-core.scm +++ b/gnucash/report/report-core.scm @@ -805,31 +805,31 @@ not found."))) (lambda (k v p) (if (equal? (gnc:report-template-name v) report) (cons v p) p)) '() *gnc:_report-templates_*))) -(define-public (gnc:cmdline-report-list) +(define-public (gnc:cmdline-report-list port) (for-each (lambda (template) - (stderr-log "* ~a ~a\n" - (if (gnc:report-template-parent-type template) "C" " ") - (gnc:report-template-name template))) + (format port "* ~a ~a\n" + (if (gnc:report-template-parent-type template) "C" " ") + (gnc:report-template-name template))) (sort (hash-fold (lambda (k v p) (if (gnc:report-template-in-menu? v) (cons v p) p)) '() *gnc:_report-templates_*) (lambda (a b) (stringtemplates report))) (cond ((null? templates) (stderr-log "Cannot find ~s. Valid reports:\n" report) - (gnc:cmdline-report-list)) + (gnc:cmdline-report-list (current-error-port))) (else (for-each (lambda (template) (let* ((options-gen (gnc:report-template-options-generator template))) - (stderr-log "\n* guid: ~a\n~a" - (gnc:report-template-report-guid template) - (gnc:html-render-options-changed (options-gen) #t)))) + (format port "\n* guid: ~a\n~a" + (gnc:report-template-report-guid template) + (gnc:html-render-options-changed (options-gen) #t)))) templates))))) (define-public (gnc:cmdline-run-report report export-type output-file dry-run?) @@ -845,12 +845,12 @@ not found."))) (cond ((null? templates) (stderr-log "Cannot find ~s. Valid reports:\n" report) - (gnc:cmdline-report-list) + (gnc:cmdline-report-list (current-error-port)) (stderr-log "\n")) ((pair? (cdr templates)) (stderr-log "~s matches multiple reports. Select guid instead:\n" report) - (gnc:cmdline-report-show report) + (gnc:cmdline-report-show report (current-error-port)) (stderr-log "\n")) (export-type (template-export report (car templates)