gnucash maint: Multiple changes pushed
Christopher Lam
clam at code.gnucash.org
Wed Aug 5 06:41:38 EDT 2020
Updated via https://github.com/Gnucash/gnucash/commit/7df7e383 (commit)
via https://github.com/Gnucash/gnucash/commit/e75150c5 (commit)
from https://github.com/Gnucash/gnucash/commit/24e288ae (commit)
commit 7df7e383c2013fe8225a114a1b40d7268112be65
Merge: 24e288ae4 e75150c5c
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Wed Aug 5 18:41:05 2020 +0800
Merge branch 'maint-show-report-with-datafile' into maint #755
commit e75150c5c6c7bd3c76581430a0b3b148a720a3c0
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Sun Jul 12 23:52:18 2020 +0800
[gnucash-cli] -R show should accept & try load datafile
* file_to_load argument, if present, would be a candidate for loading.
* if loading fails, show report details anyway.
diff --git a/gnucash/gnucash-cli.cpp b/gnucash/gnucash-cli.cpp
index ec2a34a3d..20f78ff8a 100644
--- a/gnucash/gnucash-cli.cpp
+++ b/gnucash/gnucash-cli.cpp
@@ -103,7 +103,8 @@ 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"
+ " show: \tDescribe the options modified in the named report. A datafile \
+may be specified to describe some saved options.\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"))
@@ -154,13 +155,19 @@ 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.
+
+ // The command "list" does *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 ();
+
+ // The command "show" does test&pass the m_file_to_load
+ // argument, and will attempt to load datafile prior to
+ // describing report. If loading fails, it will continue
+ // showing report options.
else if (*m_report_cmd == "show")
if (!m_report_name || m_report_name->empty())
{
@@ -169,7 +176,7 @@ Gnucash::GnucashCli::start ([[maybe_unused]] int argc, [[maybe_unused]] char **a
return 1;
}
else
- return Gnucash::report_show (m_report_name);
+ return Gnucash::report_show (m_file_to_load, 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 cda95f3de..d39b1c3fd 100644
--- a/gnucash/gnucash-commands.cpp
+++ b/gnucash/gnucash-commands.cpp
@@ -203,6 +203,7 @@ scm_run_report (void *data,
struct show_report_args {
+ const std::string file_to_load;
const std::string show_report;
};
@@ -218,6 +219,20 @@ scm_report_show (void *data,
scm_c_use_module ("gnucash reports");
gnc_report_init ();
+ if (!args->file_to_load.empty())
+ {
+ auto datafile = args->file_to_load.c_str();
+ PINFO ("Loading datafile %s...\n", datafile);
+
+ auto session = gnc_get_current_session ();
+ if (session)
+ {
+ qof_session_begin (session, datafile, SESSION_READ_ONLY);
+ if (qof_session_get_error (session) == ERR_BACKEND_NO_ERR)
+ qof_session_load (session, report_session_percentage);
+ }
+ }
+
scm_call_2 (scm_c_eval_string ("gnc:cmdline-report-show"),
scm_from_utf8_string (args->show_report.c_str ()),
scm_current_output_port ());
@@ -267,9 +282,11 @@ Gnucash::run_report (const bo_str& file_to_load,
}
int
-Gnucash::report_show (const bo_str& show_report)
+Gnucash::report_show (const bo_str& file_to_load,
+ const bo_str& show_report)
{
- auto args = show_report_args { show_report ? *show_report : std::string() };
+ auto args = show_report_args { file_to_load ? *file_to_load : std::string(),
+ show_report ? *show_report : std::string() };
if (show_report && !show_report->empty())
scm_boot_guile (0, nullptr, scm_report_show, &args);
diff --git a/gnucash/gnucash-commands.hpp b/gnucash/gnucash-commands.hpp
index d55f3d169..01511d584 100644
--- a/gnucash/gnucash-commands.hpp
+++ b/gnucash/gnucash-commands.hpp
@@ -38,6 +38,7 @@ namespace Gnucash {
const bo_str& export_type,
const bo_str& output_file);
int report_list (void);
- int report_show (const bo_str& run_report);
+ int report_show (const bo_str& file_to_load,
+ const bo_str& run_report);
}
#endif
Summary of changes:
gnucash/gnucash-cli.cpp | 21 ++++++++++++++-------
gnucash/gnucash-commands.cpp | 21 +++++++++++++++++++--
gnucash/gnucash-commands.hpp | 3 ++-
3 files changed, 35 insertions(+), 10 deletions(-)
More information about the gnucash-changes
mailing list