gnucash master: cli-reports: if run-report matches multiple, offer choices
Christopher Lam
clam at code.gnucash.org
Sat May 30 11:19:40 EDT 2020
Updated via https://github.com/Gnucash/gnucash/commit/b0effbc3 (commit)
from https://github.com/Gnucash/gnucash/commit/ad826e0f (commit)
commit b0effbc36fd26682be29a662526f90dd2d9a285c
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Sat May 30 23:10:31 2020 +0800
cli-reports: if run-report matches multiple, offer choices
If --run-report="Reportname" matches multiple reports, offer a
disambiguation. Will show guid and display the options selected in the
saved report. Example:
"Multicolumn View" matches multiple reports. Select guid instead:
* guid: 2f17ecb535f24a3a9f314bc5855569e5
General / Number of columns: 2.0
General / Report name: A saved-report based on multicolumn-view
General / Stylesheet: Easy
* guid: d8ba4a2e89e8479ca9f6eccdeb164588
diff --git a/gnucash/report/report-core.scm b/gnucash/report/report-core.scm
index 8db4eb14e..a2f341b76 100644
--- a/gnucash/report/report-core.scm
+++ b/gnucash/report/report-core.scm
@@ -800,24 +800,22 @@ not found.")))
(display "done!\n" (current-error-port))))))
(define-public (gnc:cmdline-run-report report export-type output-file dry-run?)
- (let ((template (or (gnc:find-report-template report)
- (let ((retval #f))
- (hash-for-each
- (lambda (report-guid template)
- (when (equal? (gnc:report-template-name template) report)
- (set! retval template)))
- *gnc:_report-templates_*)
- retval))))
+ (let ((templates (or (and=> (gnc:find-report-template report) list)
+ (hash-fold
+ (lambda (report-guid template prev)
+ (if (equal? (gnc:report-template-name template) report)
+ (cons template prev) prev))
+ '() *gnc:_report-templates_*))))
(define (run-report output-port)
(display
(gnc:report-render-html
(gnc-report-find
(gnc:make-report
- (gnc:report-template-report-guid template))) #t) output-port))
+ (gnc:report-template-report-guid (car templates)))) #t) output-port))
(cond
- ((not template)
+ ((null? templates)
(stderr-log "Cannot find ~s. Valid reports:\n" report)
(for-each
(lambda (pair)
@@ -831,7 +829,21 @@ not found.")))
(gnc:report-template-name (cdr a))
(gnc:report-template-name (cdr b))))))
(stderr-log "\n"))
- (export-type (template-export report template export-type output-file dry-run?))
+
+ ((pair? (cdr templates))
+ (stderr-log "~s matches multiple reports. Select guid instead:\n" report)
+ (for-each
+ (lambda (template)
+ (let* ((options-gen (gnc:report-template-options-generator template))
+ (options (options-gen)))
+ (stderr-log "\n* guid: ~a\n~a"
+ (gnc:report-template-report-guid template)
+ (gnc:html-render-options-changed options #t))))
+ templates)
+ (stderr-log "\n"))
+
+ (export-type (template-export report (car templates)
+ export-type output-file dry-run?))
(dry-run? #t)
(output-file
(format (current-error-port) "Saving report to ~a..." output-file)
Summary of changes:
gnucash/report/report-core.scm | 34 +++++++++++++++++++++++-----------
1 file changed, 23 insertions(+), 11 deletions(-)
More information about the gnucash-changes
mailing list