gnucash master: Multiple changes pushed

Christopher Lam clam at code.gnucash.org
Sat Jun 6 08:03:03 EDT 2020


Updated	 via  https://github.com/Gnucash/gnucash/commit/747ad968 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/25e55cee (commit)
	 via  https://github.com/Gnucash/gnucash/commit/4d921c67 (commit)
	from  https://github.com/Gnucash/gnucash/commit/f8fdb95e (commit)



commit 747ad9680243cb227cda88bed29d48fd692c53b9
Merge: f8fdb95ea 25e55cee8
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Jun 6 19:27:00 2020 +0800

    Merge branch 'master-cli-report-upgrades' #733


commit 25e55cee82de57eb4c2c6cb64f3cb2fd07207ba6
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Jun 6 12:16:52 2020 +0800

    [cli-reports] implement --report show

diff --git a/gnucash/gnucash-cli.cpp b/gnucash/gnucash-cli.cpp
index 771c11e21..03e98c6e3 100644
--- a/gnucash/gnucash-cli.cpp
+++ b/gnucash/gnucash-cli.cpp
@@ -102,6 +102,7 @@ Gnucash::GnucashCli::configure_program_options (void)
     ("report,R", bpo::value (&m_report_cmd),
      _("Execute report related commands. The following commands are supported.\n\n"
      "  list: \tLists available reports.\n"
+     "  show: \tDescribe the options modified in the named report.\n"
      "  run: \tRun the named report in the given GnuCash datafile.\n"))
     ("name", bpo::value (&m_report_name),
      _("Name of the report to run\n"))
@@ -151,8 +152,22 @@ Gnucash::GnucashCli::start ([[maybe_unused]] int argc, [[maybe_unused]] char **a
                 return Gnucash::run_report(m_file_to_load, m_report_name,
                                            m_export_type, m_output_file);
         }
+        // the following two commands list and show do *not* test&pass
+        // the m_file_to_load argument because the reports are global
+        // rather than per-file objects. In the future, saved reports
+        // may be saved into the datafile, therefore one will need to
+        // be specified for loading.
         else if (*m_report_cmd == "list")
                 return Gnucash::report_list ();
+        else if (*m_report_cmd == "show")
+            if (!m_report_name || m_report_name->empty())
+            {
+                std::cerr << bl::translate("Missing --name parameter") << "\n\n"
+                          << *m_opt_desc.get();
+                return 1;
+            }
+            else
+                return Gnucash::report_show (m_report_name);
         else
         {
             std::cerr << bl::format (bl::translate("Unknown report command '{1}'")) % *m_report_cmd << "\n\n"
diff --git a/gnucash/gnucash-commands.cpp b/gnucash/gnucash-commands.cpp
index 428e8aed5..9627db0f0 100644
--- a/gnucash/gnucash-commands.cpp
+++ b/gnucash/gnucash-commands.cpp
@@ -197,6 +197,30 @@ scm_run_report (void *data,
     return;
 }
 
+
+struct show_report_args {
+    const std::string& show_report;
+};
+
+static void
+scm_report_show (void *data,
+                [[maybe_unused]] int argc, [[maybe_unused]] char **argv)
+{
+    auto args = static_cast<show_report_args*>(data);
+
+    scm_c_eval_string("(debug-set! stack 200000)");
+    scm_c_use_module ("gnucash utilities");
+    scm_c_use_module ("gnucash app-utils");
+    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()));
+    gnc_shutdown (0);
+    return;
+}
+
+
 static void
 scm_report_list ([[maybe_unused]] void *data,
                  [[maybe_unused]] int argc, [[maybe_unused]] char **argv)
@@ -236,6 +260,16 @@ Gnucash::run_report (const bo_str& file_to_load,
     return 0;
 }
 
+int
+Gnucash::report_show (const bo_str& show_report)
+{
+    auto args = show_report_args { show_report ? *show_report : std::string() };
+    if (show_report && !show_report->empty())
+        scm_boot_guile (0, nullptr, scm_report_show, &args);
+
+    return 0;
+}
+
 int
 Gnucash::report_list (void)
 {
diff --git a/gnucash/gnucash-commands.hpp b/gnucash/gnucash-commands.hpp
index db0b7c6df..d55f3d169 100644
--- a/gnucash/gnucash-commands.hpp
+++ b/gnucash/gnucash-commands.hpp
@@ -38,5 +38,6 @@ namespace Gnucash {
                     const bo_str& export_type,
                     const bo_str& output_file);
     int report_list (void);
+    int report_show (const bo_str& run_report);
 }
 #endif
diff --git a/gnucash/report/report-core.scm b/gnucash/report/report-core.scm
index d9d2182b8..804b85625 100644
--- a/gnucash/report/report-core.scm
+++ b/gnucash/report/report-core.scm
@@ -799,6 +799,12 @@ not found.")))
        (assoc-ref parent-export-types export-type) output-file)
       (display "done!\n" (current-error-port))))))
 
+(define (reportname->templates report)
+  (or (and=> (gnc:find-report-template report) list)
+      (hash-fold
+       (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)
   (for-each
    (lambda (template)
@@ -811,13 +817,23 @@ not found.")))
          (lambda (a b)
            (string<? (gnc:report-template-name a) (gnc:report-template-name b))))))
 
+(define-public (gnc:cmdline-report-show report)
+  (let ((templates (reportname->templates report)))
+    (cond
+     ((null? templates)
+      (stderr-log "Cannot find ~s. Valid reports:\n" report)
+      (gnc:cmdline-report-list))
+     (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))))
+       templates)))))
+
 (define-public (gnc:cmdline-run-report report export-type output-file dry-run?)
-  (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_*))))
+  (let ((templates (reportname->templates report)))
 
     (define (run-report output-port)
       (display
@@ -834,14 +850,7 @@ not found.")))
 
      ((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)
+      (gnc:cmdline-report-show report)
       (stderr-log "\n"))
 
      (export-type (template-export report (car templates)

commit 4d921c67c38832a5f8314abd716103a90b6434a1
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Jun 6 11:51:12 2020 +0800

    [cli-reports] implement --report list
    
    Lists available reports.

diff --git a/gnucash/gnucash-cli.cpp b/gnucash/gnucash-cli.cpp
index d801473f5..771c11e21 100644
--- a/gnucash/gnucash-cli.cpp
+++ b/gnucash/gnucash-cli.cpp
@@ -100,7 +100,8 @@ Gnucash::GnucashCli::configure_program_options (void)
     bpo::options_description report_options(_("Report Generation Options"));
     report_options.add_options()
     ("report,R", bpo::value (&m_report_cmd),
-     _("Execute report related commands. Currently only one command is supported.\n\n"
+     _("Execute report related commands. The following commands are supported.\n\n"
+     "  list: \tLists available reports.\n"
      "  run: \tRun the named report in the given GnuCash datafile.\n"))
     ("name", bpo::value (&m_report_name),
      _("Name of the report to run\n"))
@@ -150,6 +151,8 @@ Gnucash::GnucashCli::start ([[maybe_unused]] int argc, [[maybe_unused]] char **a
                 return Gnucash::run_report(m_file_to_load, m_report_name,
                                            m_export_type, m_output_file);
         }
+        else if (*m_report_cmd == "list")
+                return Gnucash::report_list ();
         else
         {
             std::cerr << bl::format (bl::translate("Unknown report command '{1}'")) % *m_report_cmd << "\n\n"
diff --git a/gnucash/gnucash-commands.cpp b/gnucash/gnucash-commands.cpp
index e84d25cbf..428e8aed5 100644
--- a/gnucash/gnucash-commands.cpp
+++ b/gnucash/gnucash-commands.cpp
@@ -197,6 +197,20 @@ scm_run_report (void *data,
     return;
 }
 
+static void
+scm_report_list ([[maybe_unused]] void *data,
+                 [[maybe_unused]] int argc, [[maybe_unused]] char **argv)
+{
+    scm_c_eval_string("(debug-set! stack 200000)");
+    scm_c_use_module ("gnucash app-utils");
+    scm_c_use_module ("gnucash reports");
+    gnc_report_init ();
+
+    scm_call_0 (scm_c_eval_string ("gnc:cmdline-report-list"));
+    gnc_shutdown (0);
+    return;
+}
+
 int
 Gnucash::add_quotes (const bo_str& uri)
 {
@@ -221,3 +235,10 @@ Gnucash::run_report (const bo_str& file_to_load,
 
     return 0;
 }
+
+int
+Gnucash::report_list (void)
+{
+    scm_boot_guile (0, nullptr, scm_report_list, NULL);
+    return 0;
+}
diff --git a/gnucash/gnucash-commands.hpp b/gnucash/gnucash-commands.hpp
index 328d18513..db0b7c6df 100644
--- a/gnucash/gnucash-commands.hpp
+++ b/gnucash/gnucash-commands.hpp
@@ -37,6 +37,6 @@ namespace Gnucash {
                     const bo_str& run_report,
                     const bo_str& export_type,
                     const bo_str& output_file);
-
+    int report_list (void);
 }
 #endif
diff --git a/gnucash/report/report-core.scm b/gnucash/report/report-core.scm
index a2f341b76..d9d2182b8 100644
--- a/gnucash/report/report-core.scm
+++ b/gnucash/report/report-core.scm
@@ -799,6 +799,18 @@ not found.")))
        (assoc-ref parent-export-types export-type) output-file)
       (display "done!\n" (current-error-port))))))
 
+(define-public (gnc:cmdline-report-list)
+  (for-each
+   (lambda (template)
+     (stderr-log "* ~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-run-report report export-type output-file dry-run?)
   (let ((templates (or (and=> (gnc:find-report-template report) list)
                        (hash-fold
@@ -817,17 +829,7 @@ not found.")))
     (cond
      ((null? templates)
       (stderr-log "Cannot find ~s. Valid reports:\n" report)
-      (for-each
-       (lambda (pair)
-         (when (gnc:report-template-in-menu? (cdr pair))
-           (stderr-log "* ~a ~a\n"
-                       (if (gnc:report-template-parent-type (cdr pair)) "C" " ")
-                       (gnc:report-template-name (cdr pair)))))
-       (sort (hash-map->list cons *gnc:_report-templates_*)
-             (lambda (a b)
-               (string<?
-                (gnc:report-template-name (cdr a))
-                (gnc:report-template-name (cdr b))))))
+      (gnc:cmdline-report-list)
       (stderr-log "\n"))
 
      ((pair? (cdr templates))



Summary of changes:
 gnucash/gnucash-cli.cpp        | 20 +++++++++++++-
 gnucash/gnucash-commands.cpp   | 55 +++++++++++++++++++++++++++++++++++++
 gnucash/gnucash-commands.hpp   |  3 ++-
 gnucash/report/report-core.scm | 61 +++++++++++++++++++++++++-----------------
 4 files changed, 112 insertions(+), 27 deletions(-)



More information about the gnucash-changes mailing list