diff --git a/gnucash/gnucash-cli.cpp b/gnucash/gnucash-cli.cpp index f40f1a2060..607392ba73 100644 --- a/gnucash/gnucash-cli.cpp +++ b/gnucash/gnucash-cli.cpp @@ -55,7 +55,7 @@ namespace Gnucash { private: void configure_program_options (void); - std::string m_quotes_file; + bool m_add_quotes; }; } @@ -70,12 +70,11 @@ Gnucash::GnucashCli::parse_command_line (int argc, char **argv) { Gnucash::CoreApp::parse_command_line (argc, argv); + m_add_quotes = m_opt_map["add-price-quotes"].as(); + if (m_opt_map.count ("namespace")) gnc_prefs_set_namespace_regexp(m_opt_map["namespace"]. as().c_str()); - - if (m_opt_map.count ("add-price-quotes")) - m_quotes_file = m_opt_map["add-price-quotes"].as(); } // Define command line options specific to gnucash-cli. @@ -84,7 +83,7 @@ Gnucash::GnucashCli::configure_program_options (void) { bpo::options_description quotes_options(_("Price Retrieval Options")); quotes_options.add_options() - ("add-price-quotes", bpo::value(), + ("add-price-quotes", bpo::bool_switch(), N_("Add price quotes to given GnuCash datafile.\n")) ("namespace", bpo::value(), N_("Regular expression determining which namespace commodities will be retrieved")); @@ -97,10 +96,20 @@ Gnucash::GnucashCli::start ([[maybe_unused]] int argc, [[maybe_unused]] char **a { Gnucash::CoreApp::start(); - if (m_quotes_file.empty()) - return 1; - - return Gnucash::add_quotes (m_quotes_file); + if (m_add_quotes) + { + if (m_file_to_load.empty()) + { + std::cerr << bl::translate("Missing data file parameter") << "\n\n" + << *m_opt_desc.get(); + return 1; + } + else + return Gnucash::add_quotes (m_file_to_load); + } + + + return 1; } int diff --git a/gnucash/gnucash-core-app.cpp b/gnucash/gnucash-core-app.cpp index 3e6f415c96..3017a9bb8f 100644 --- a/gnucash/gnucash-core-app.cpp +++ b/gnucash/gnucash-core-app.cpp @@ -622,6 +622,9 @@ Gnucash::CoreApp::parse_command_line (int argc, char **argv) m_log_to_filename = m_opt_map["logto"]. as().c_str(); + if (m_opt_map.count ("input-file")) + m_file_to_load = m_opt_map["input-file"].as(); + if (args_remaining) file_to_load = args_remaining[0]; } @@ -645,7 +648,11 @@ Gnucash::CoreApp::add_common_program_options (void) ("logto", bpo::value(), N_("File to log into; defaults to \"/tmp/gnucash.trace\"; can be \"stderr\" or \"stdout\".")) ("gsettings-prefix", bpo::value(), - N_("Set the prefix for gsettings schemas for gsettings queries. This can be useful to have a different settings tree while debugging.")); + N_("Set the prefix for gsettings schemas for gsettings queries. This can be useful to have a different settings tree while debugging.")) + ("input-file", bpo::value(), + N_("[datafile]")); + + m_pos_opt_desc.add("input-file", -1); m_opt_desc->add (common_options); } diff --git a/gnucash/gnucash-core-app.hpp b/gnucash/gnucash-core-app.hpp index 8c65443ba6..e7e53553c9 100644 --- a/gnucash/gnucash-core-app.hpp +++ b/gnucash/gnucash-core-app.hpp @@ -45,6 +45,7 @@ protected: int gtk_show_help = 0; std::string m_app_name; std::string tagline; + std::string m_file_to_load; std::unique_ptr m_opt_desc; bpo::variables_map m_opt_map; diff --git a/gnucash/gnucash.cpp b/gnucash/gnucash.cpp index 00a715b787..2469ebbfba 100644 --- a/gnucash/gnucash.cpp +++ b/gnucash/gnucash.cpp @@ -304,8 +304,7 @@ namespace Gnucash { void configure_program_options (void); std::string m_gtk_help_msg; - std::string m_file_to_load; - std::string m_quotes_file; // Deprecated will be removed in gnucash 5.0 + bool m_add_quotes; // Deprecated will be removed in gnucash 5.0 }; } @@ -327,15 +326,11 @@ Gnucash::Gnucash::parse_command_line (int argc, char **argv) exit(0); } + m_add_quotes = m_opt_map["add-price-quotes"].as(); + if (m_opt_map.count ("namespace")) gnc_prefs_set_namespace_regexp (m_opt_map["namespace"]. as().c_str()); - - if (m_opt_map.count ("add-price-quotes")) - m_quotes_file = m_opt_map["add-price-quotes"].as(); - - if (m_opt_map.count ("input-file")) - m_file_to_load = m_opt_map["input-file"].as(); } // Define command line options specific to gnucash. @@ -361,18 +356,14 @@ Gnucash::Gnucash::configure_program_options (void) bpo::options_description depr_options(_("Deprecated Options")); depr_options.add_options() - ("add-price-quotes", bpo::value(), + ("add-price-quotes", bpo::bool_switch(), N_("Add price quotes to given GnuCash datafile.\n" "Note this option has been deprecated and will be removed in GnuCash 5.0.\n" "Please use \"gnucash-cli --add-price-quotes\" instead.")) ("namespace", bpo::value(), N_("Regular expression determining which namespace commodities will be retrieved" "Note this option has been deprecated and will be removed in GnuCash 5.0.\n" - "Please use \"gnucash-cli --add-price-quotes\" instead.")) - ("input-file", bpo::value(), - N_("[datafile]")); - - m_pos_opt_desc.add("input-file", -1); + "Please use \"gnucash-cli --add-price-quotes\" instead.")); m_opt_desc->add (app_options).add (depr_options); } @@ -384,11 +375,18 @@ Gnucash::Gnucash::start ([[maybe_unused]] int argc, [[maybe_unused]] char **argv // Test for the deprecated add-price-quotes option and run it // Will be removed in 5.0 - if (!m_quotes_file.empty()) + if (m_add_quotes) { std::cerr << bl::translate ("The '--add-price-quotes' option to gnucash has been deprecated and will be removed in GnuCash 5.0. " "Please use 'gnucash-cli --add-price-quotes' instead.") << "\n"; - return add_quotes (m_quotes_file); + if (m_file_to_load.empty()) + { + std::cerr << bl::translate("Missing data file parameter") << "\n\n" + << *m_opt_desc.get(); + return 1; + } + else + return add_quotes (m_file_to_load); } /* Now the module files are looked up, which might cause some library