From cee52d4f918a62686db34174f24c24124ce9f11c Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Fri, 5 Jun 2020 19:46:17 +0200 Subject: [PATCH] Convert '--run-report' to '--report run' to accomodate for additonal report commands Note this required the introduction of a '--name' parameter for the report name to run. Without it the command line would have to support a variable number of positional parameters, depending on the context (quotes or report) and that would complicate the parsing considerably. --- gnucash/gnucash-cli.cpp | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/gnucash/gnucash-cli.cpp b/gnucash/gnucash-cli.cpp index c9d3526535..d801473f5e 100644 --- a/gnucash/gnucash-cli.cpp +++ b/gnucash/gnucash-cli.cpp @@ -59,7 +59,8 @@ namespace Gnucash { boost::optional m_quotes_cmd; boost::optional m_namespace; - boost::optional m_run_report; + boost::optional m_report_cmd; + boost::optional m_report_name; boost::optional m_export_type; boost::optional m_output_file; }; @@ -90,7 +91,7 @@ Gnucash::GnucashCli::configure_program_options (void) bpo::options_description quotes_options(_("Price Quotes Retrieval Options")); quotes_options.add_options() ("quotes,Q", bpo::value (&m_quotes_cmd), - _("Run price quote related commands. Currently only one command is supported.\n\n" + _("Execute price quote related commands. Currently only one command is supported.\n\n" " get: \tFetch current quotes for all foreign currencies and stocks in the given GnuCash datafile.\n")) ("namespace", bpo::value (&m_namespace), _("Regular expression determining which namespace commodities will be retrieved for")); @@ -98,8 +99,11 @@ Gnucash::GnucashCli::configure_program_options (void) bpo::options_description report_options(_("Report Generation Options")); report_options.add_options() - ("run-report", bpo::value (&m_run_report), - _("Runs a report\n")) + ("report,R", bpo::value (&m_report_cmd), + _("Execute report related commands. Currently only one command is supported.\n\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")) ("export-type", bpo::value (&m_export_type), _("Specify export type\n")) ("output-file", bpo::value (&m_output_file), @@ -129,20 +133,29 @@ Gnucash::GnucashCli::start ([[maybe_unused]] int argc, [[maybe_unused]] char **a return 1; } else - return Gnucash::add_quotes (*m_file_to_load); + return Gnucash::add_quotes (m_file_to_load); } - if (m_run_report && !m_run_report->empty()) + if (m_report_cmd) { - if (!m_file_to_load || m_file_to_load->empty()) + if (*m_report_cmd == "run") { - std::cerr << bl::translate("Missing data file parameter") << "\n\n" - << *m_opt_desc.get(); - return 1; + if (!m_file_to_load || m_file_to_load->empty()) + { + std::cerr << bl::translate("Missing data file parameter") << "\n\n" + << *m_opt_desc.get(); + return 1; + } + else + return Gnucash::run_report(m_file_to_load, m_report_name, + m_export_type, m_output_file); } else - return Gnucash::run_report(*m_file_to_load, m_run_report, - m_export_type, m_output_file); + { + std::cerr << bl::format (bl::translate("Unknown report command '{1}'")) % *m_report_cmd << "\n\n" + << *m_opt_desc.get(); + return 1; + } } return 1; }