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
This commit is contained in:
Christopher Lam
2020-05-30 23:10:31 +08:00
parent ad826e0f44
commit b0effbc36f

View File

@@ -800,24 +800,22 @@ not found.")))
(display "done!\n" (current-error-port)))))) (display "done!\n" (current-error-port))))))
(define-public (gnc:cmdline-run-report report export-type output-file dry-run?) (define-public (gnc:cmdline-run-report report export-type output-file dry-run?)
(let ((template (or (gnc:find-report-template report) (let ((templates (or (and=> (gnc:find-report-template report) list)
(let ((retval #f)) (hash-fold
(hash-for-each (lambda (report-guid template prev)
(lambda (report-guid template) (if (equal? (gnc:report-template-name template) report)
(when (equal? (gnc:report-template-name template) report) (cons template prev) prev))
(set! retval template))) '() *gnc:_report-templates_*))))
*gnc:_report-templates_*)
retval))))
(define (run-report output-port) (define (run-report output-port)
(display (display
(gnc:report-render-html (gnc:report-render-html
(gnc-report-find (gnc-report-find
(gnc:make-report (gnc:make-report
(gnc:report-template-report-guid template))) #t) output-port)) (gnc:report-template-report-guid (car templates)))) #t) output-port))
(cond (cond
((not template) ((null? templates)
(stderr-log "Cannot find ~s. Valid reports:\n" report) (stderr-log "Cannot find ~s. Valid reports:\n" report)
(for-each (for-each
(lambda (pair) (lambda (pair)
@@ -831,7 +829,21 @@ not found.")))
(gnc:report-template-name (cdr a)) (gnc:report-template-name (cdr a))
(gnc:report-template-name (cdr b)))))) (gnc:report-template-name (cdr b))))))
(stderr-log "\n")) (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) (dry-run? #t)
(output-file (output-file
(format (current-error-port) "Saving report to ~a..." output-file) (format (current-error-port) "Saving report to ~a..." output-file)