Skip to content

Commit

Permalink
Make options that don't take arguments bool_switch type
Browse files Browse the repository at this point in the history
This means they will always exist in the value store after parsing and
are set to true or false. This eliminates the need to test for their
existence first.
  • Loading branch information
gjanssens committed May 29, 2020
1 parent 88ed957 commit 1600341
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
16 changes: 8 additions & 8 deletions gnucash/gnucash-core-app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ Gnucash::CoreApp::parse_command_line (int argc, char **argv)
#endif
}

if (m_opt_map.count ("version"))
if (m_opt_map["version"].as<bool>())
{
bl::format rel_fmt (bl::translate ("GnuCash {1}"));
bl::format dev_fmt (bl::translate ("GnuCash {1} development version"));
Expand All @@ -601,14 +601,14 @@ Gnucash::CoreApp::parse_command_line (int argc, char **argv)
exit(0);
}

if (m_opt_map.count ("help"))
if (m_opt_map["help"].as<bool>())
{
std::cout << *m_opt_desc.get() << "\n";
exit(0);
}

gnc_prefs_set_debugging (m_opt_map.count ("debug"));
gnc_prefs_set_extra (m_opt_map.count ("extra"));
gnc_prefs_set_debugging (m_opt_map["debug"].as<bool>());
gnc_prefs_set_extra (m_opt_map["extra"].as<bool>());

if (m_opt_map.count ("gsettings-prefix"))
gnc_gsettings_set_prefix (m_opt_map["gsettings-prefix"].
Expand All @@ -630,13 +630,13 @@ Gnucash::CoreApp::add_common_program_options (void)

bpo::options_description common_options(_("Common Options"));
common_options.add_options()
("help,h",
("help,h", bpo::bool_switch(),
N_("Show this help message"))
("version,v",
("version,v", bpo::bool_switch(),
N_("Show GnuCash version"))
("debug",
("debug", bpo::bool_switch(),
N_("Enable debugging mode: provide deep detail in the logs.\nThis is equivalent to: --log \"=info\" --log \"qof=info\" --log \"gnc=info\""))
("extra",
("extra", bpo::bool_switch(),
N_("Enable extra/development/debugging features."))
("log", bpo::value< std::vector<std::string> >(),
N_("Log level overrides, of the form \"modulename={debug,info,warn,crit,error}\"\nExamples: \"--log qof=debug\" or \"--log gnc.backend.file.sx=info\"\nThis can be invoked multiple times."))
Expand Down
7 changes: 4 additions & 3 deletions gnucash/gnucash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ Gnucash::Gnucash::parse_command_line (int argc, char **argv)
{
Gnucash::CoreApp::parse_command_line (argc, argv);

if (m_opt_map.count ("help-gtk"))
if (m_opt_map["help-gtk"].as<bool>())
{
std::cout << m_gtk_help_msg;
exit(0);
Expand Down Expand Up @@ -411,9 +411,10 @@ Gnucash::Gnucash::configure_program_options (void)

bpo::options_description app_options(_("Application Options"));
app_options.add_options()
("nofile",
("nofile", bpo::bool_switch(),
N_("Do not load the last file opened"))
("help-gtk", _("Show help for gtk options"))
("help-gtk", bpo::bool_switch(),
_("Show help for gtk options"))
("add-price-quotes", bpo::value<std::string>(),
N_("Add price quotes to given GnuCash datafile.\n"
"Note this option has been deprecated and will be removed in GnuCash 5.0.\n"
Expand Down

0 comments on commit 1600341

Please sign in to comment.