gnucash master: [gnucash-cli] --report show/list outputs to stdout

Christopher Lam clam at code.gnucash.org
Sat Jun 13 04:35:33 EDT 2020


Updated	 via  https://github.com/Gnucash/gnucash/commit/51d00fcb (commit)
	from  https://github.com/Gnucash/gnucash/commit/e5a14b89 (commit)



commit 51d00fcbe54dd30cc56755eefa0f0fb6f3b83e2b
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Jun 13 16:31:38 2020 +0800

    [gnucash-cli] --report show/list outputs to stdout
    
    and their error messages output to stderr

diff --git a/gnucash/gnucash-commands.cpp b/gnucash/gnucash-commands.cpp
index 9627db0f0..5ee2669d8 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 804b85625..3dce45f05 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)
            (string<? (gnc:report-template-name a) (gnc:report-template-name b))))))
 
-(define-public (gnc:cmdline-report-show report)
+(define-public (gnc:cmdline-report-show report port)
   (let ((templates (reportname->templates 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)



Summary of changes:
 gnucash/gnucash-commands.cpp   |  8 +++++---
 gnucash/report/report-core.scm | 22 +++++++++++-----------
 2 files changed, 16 insertions(+), 14 deletions(-)



More information about the gnucash-changes mailing list