Bug 797800 - [help screen items] clarification welcome

This fixes the presence of the 'input-file' command line option.
It's an implementation detail that wasn't meant to be listed in help.
The way to fix it is keeping two option_description variables. One
with all possible values to parse and one with only those to present
to the user
This commit is contained in:
Geert Janssens 2020-06-12 17:43:40 +02:00
parent 7754f035c4
commit 49e394e3bd
4 changed files with 30 additions and 16 deletions

View File

@ -95,7 +95,8 @@ Gnucash::GnucashCli::configure_program_options (void)
" get: \tFetch current quotes for all foreign currencies and stocks in the given GnuCash datafile.\n")) " get: \tFetch current quotes for all foreign currencies and stocks in the given GnuCash datafile.\n"))
("namespace", bpo::value (&m_namespace), ("namespace", bpo::value (&m_namespace),
_("Regular expression determining which namespace commodities will be retrieved for")); _("Regular expression determining which namespace commodities will be retrieved for"));
m_opt_desc->add (quotes_options); m_opt_desc_display->add (quotes_options);
m_opt_desc_all.add (quotes_options);
bpo::options_description report_options(_("Report Generation Options")); bpo::options_description report_options(_("Report Generation Options"));
report_options.add_options() report_options.add_options()
@ -110,7 +111,8 @@ Gnucash::GnucashCli::configure_program_options (void)
_("Specify export type\n")) _("Specify export type\n"))
("output-file", bpo::value (&m_output_file), ("output-file", bpo::value (&m_output_file),
_("Output file for report\n")); _("Output file for report\n"));
m_opt_desc->add (report_options); m_opt_desc_display->add (report_options);
m_opt_desc_all.add (report_options);
} }
@ -124,14 +126,14 @@ Gnucash::GnucashCli::start ([[maybe_unused]] int argc, [[maybe_unused]] char **a
if (*m_quotes_cmd != "get") if (*m_quotes_cmd != "get")
{ {
std::cerr << bl::format (bl::translate("Unknown quotes command '{1}'")) % *m_quotes_cmd << "\n\n" std::cerr << bl::format (bl::translate("Unknown quotes command '{1}'")) % *m_quotes_cmd << "\n\n"
<< *m_opt_desc.get(); << *m_opt_desc_display.get();
return 1; return 1;
} }
if (!m_file_to_load || m_file_to_load->empty()) if (!m_file_to_load || m_file_to_load->empty())
{ {
std::cerr << bl::translate("Missing data file parameter") << "\n\n" std::cerr << bl::translate("Missing data file parameter") << "\n\n"
<< *m_opt_desc.get(); << *m_opt_desc_display.get();
return 1; return 1;
} }
else else
@ -145,7 +147,7 @@ Gnucash::GnucashCli::start ([[maybe_unused]] int argc, [[maybe_unused]] char **a
if (!m_file_to_load || m_file_to_load->empty()) if (!m_file_to_load || m_file_to_load->empty())
{ {
std::cerr << bl::translate("Missing data file parameter") << "\n\n" std::cerr << bl::translate("Missing data file parameter") << "\n\n"
<< *m_opt_desc.get(); << *m_opt_desc_display.get();
return 1; return 1;
} }
else else
@ -163,7 +165,7 @@ Gnucash::GnucashCli::start ([[maybe_unused]] int argc, [[maybe_unused]] char **a
if (!m_report_name || m_report_name->empty()) if (!m_report_name || m_report_name->empty())
{ {
std::cerr << bl::translate("Missing --name parameter") << "\n\n" std::cerr << bl::translate("Missing --name parameter") << "\n\n"
<< *m_opt_desc.get(); << *m_opt_desc_display.get();
return 1; return 1;
} }
else else
@ -171,10 +173,14 @@ Gnucash::GnucashCli::start ([[maybe_unused]] int argc, [[maybe_unused]] char **a
else else
{ {
std::cerr << bl::format (bl::translate("Unknown report command '{1}'")) % *m_report_cmd << "\n\n" std::cerr << bl::format (bl::translate("Unknown report command '{1}'")) % *m_report_cmd << "\n\n"
<< *m_opt_desc.get(); << *m_opt_desc_display.get();
return 1; return 1;
} }
} }
std::cerr << bl::translate("Missing command or option") << "\n\n"
<< *m_opt_desc_display.get();
return 1; return 1;
} }

View File

@ -516,7 +516,7 @@ Gnucash::CoreApp::CoreApp (const char* app_name)
// Now that gettext is properly initialized, set our help tagline. // Now that gettext is properly initialized, set our help tagline.
m_tagline = bl::translate("- GnuCash, accounting for personal and small business finance").str(gnc_get_boost_locale()); m_tagline = bl::translate("- GnuCash, accounting for personal and small business finance").str(gnc_get_boost_locale());
m_opt_desc = std::make_unique<bpo::options_description> m_opt_desc_display = std::make_unique<bpo::options_description>
((bl::format (bl::gettext ("{1} [options] [datafile]")) % m_app_name).str() + std::string(" ") + m_tagline); ((bl::format (bl::gettext ("{1} [options] [datafile]")) % m_app_name).str() + std::string(" ") + m_tagline);
add_common_program_options(); add_common_program_options();
} }
@ -532,13 +532,13 @@ Gnucash::CoreApp::parse_command_line (int argc, char **argv)
try try
{ {
bpo::store (bpo::command_line_parser (argc, argv). bpo::store (bpo::command_line_parser (argc, argv).
options (*m_opt_desc.get()).positional(m_pos_opt_desc).run(), m_opt_map); options (m_opt_desc_all).positional(m_pos_opt_desc).run(), m_opt_map);
bpo::notify (m_opt_map); bpo::notify (m_opt_map);
} }
catch (std::exception &e) catch (std::exception &e)
{ {
std::cerr << e.what() << "\n\n"; std::cerr << e.what() << "\n\n";
std::cerr << *m_opt_desc.get(); std::cerr << *m_opt_desc_display.get() << "\n";
exit(1); exit(1);
} }
@ -559,7 +559,7 @@ Gnucash::CoreApp::parse_command_line (int argc, char **argv)
if (m_show_help) if (m_show_help)
{ {
std::cout << *m_opt_desc.get() << "\n"; std::cout << *m_opt_desc_display.get() << "\n";
exit(0); exit(0);
} }
@ -589,13 +589,19 @@ Gnucash::CoreApp::add_common_program_options (void)
("logto", bpo::value (&m_log_to_filename), ("logto", bpo::value (&m_log_to_filename),
_("File to log into; defaults to \"/tmp/gnucash.trace\"; can be \"stderr\" or \"stdout\".")) _("File to log into; defaults to \"/tmp/gnucash.trace\"; can be \"stderr\" or \"stdout\"."))
("gsettings-prefix", bpo::value (&m_gsettings_prefix), ("gsettings-prefix", bpo::value (&m_gsettings_prefix),
_("Set the prefix for gsettings schemas for gsettings queries. This can be useful to have a different settings tree while debugging.")) _("Set the prefix for gsettings schemas for gsettings queries. This can be useful to have a different settings tree while debugging."));
bpo::options_description hidden_options(_("Hidden Options"));
hidden_options.add_options()
("input-file", bpo::value (&m_file_to_load), ("input-file", bpo::value (&m_file_to_load),
_("[datafile]")); _("[datafile]"));
m_pos_opt_desc.add("input-file", -1); m_pos_opt_desc.add("input-file", -1);
m_opt_desc->add (common_options); m_opt_desc_all.add (common_options);
m_opt_desc_all.add (hidden_options);
m_opt_desc_display->add (common_options);
} }
void void

View File

@ -51,7 +51,8 @@ protected:
boost::optional <std::string> m_log_to_filename; boost::optional <std::string> m_log_to_filename;
boost::optional <std::string> m_file_to_load; boost::optional <std::string> m_file_to_load;
std::unique_ptr<bpo::options_description> m_opt_desc; bpo::options_description m_opt_desc_all;
std::unique_ptr<bpo::options_description> m_opt_desc_display;
bpo::variables_map m_opt_map; bpo::variables_map m_opt_map;
bpo::positional_options_description m_pos_opt_desc; bpo::positional_options_description m_pos_opt_desc;

View File

@ -343,7 +343,8 @@ Gnucash::Gnucash::configure_program_options (void)
"Note this option has been deprecated and will be removed in GnuCash 5.0.\n" "Note this option has been deprecated and will be removed in GnuCash 5.0.\n"
"Please use 'gnucash-cli --quotes get --namespace <namespace> <datafile>' instead.")); "Please use 'gnucash-cli --quotes get --namespace <namespace> <datafile>' instead."));
m_opt_desc->add (app_options).add (depr_options); m_opt_desc_display->add (app_options).add (depr_options);
m_opt_desc_all.add (app_options).add (depr_options);
} }
int int
@ -360,7 +361,7 @@ Gnucash::Gnucash::start ([[maybe_unused]] int argc, [[maybe_unused]] char **argv
if (!m_file_to_load || m_file_to_load->empty()) if (!m_file_to_load || m_file_to_load->empty())
{ {
std::cerr << bl::translate("Missing data file parameter") << "\n\n" std::cerr << bl::translate("Missing data file parameter") << "\n\n"
<< *m_opt_desc.get(); << *m_opt_desc_display.get();
return 1; return 1;
} }
else else