88#include < cstring>
99#include < getopt.h>
1010#include < osmium/version.hpp>
11- #include < sstream>
1211#include < stdexcept>
1312#include < thread> // for number of threads
1413
@@ -86,7 +85,7 @@ void short_usage(char *arg0)
8685 " \t {} -h|--help\n " _format (program_name (arg0))};
8786}
8887
89- void long_usage (char const *arg0, bool verbose = false )
88+ void long_usage (char const *arg0, bool verbose)
9089{
9190 char const *const name = program_name (arg0);
9291
@@ -257,33 +256,27 @@ void long_usage(char const *arg0, bool verbose = false)
257256
258257} // anonymous namespace
259258
260- database_options_t ::database_options_t ()
261- : db(boost::none), username(boost::none), host(boost::none),
262- password (boost::none), port(boost::none)
263- {}
264-
265259std::string database_options_t::conninfo () const
266260{
267- std::ostringstream out;
261+ std::string out{ " fallback_application_name='osm2pgsql' " } ;
268262
269- out << " fallback_application_name='osm2pgsql'" ;
270- if (db) {
271- out << " dbname='" << *db << " '" ;
263+ if (!db.empty ()) {
264+ out += " dbname='{}'" _format (db);
272265 }
273- if (username) {
274- out << " user='" << *username << " ' " ;
266+ if (! username. empty () ) {
267+ out += " user='{}' " _format (username) ;
275268 }
276- if (password) {
277- out << " password='" << *password << " ' " ;
269+ if (! password. empty () ) {
270+ out += " password='{}' " _format (password) ;
278271 }
279- if (host) {
280- out << " host='" << *host << " ' " ;
272+ if (! host. empty () ) {
273+ out += " host='{}' " _format (host) ;
281274 }
282- if (port) {
283- out << " port='" << *port << " ' " ;
275+ if (! port. empty () ) {
276+ out += " port='{}' " _format (port) ;
284277 }
285278
286- return out. str () ;
279+ return out;
287280}
288281
289282options_t ::options_t ()
@@ -302,8 +295,6 @@ options_t::options_t()
302295 }
303296}
304297
305- options_t ::~options_t () {}
306-
307298static osmium::Box parse_bbox (char const *bbox)
308299{
309300 double minx, maxx, miny, maxy;
@@ -331,6 +322,8 @@ static osmium::Box parse_bbox(char const *bbox)
331322
332323options_t ::options_t (int argc, char *argv[]) : options_t ()
333324{
325+ bool help_verbose = false ; // Will be set when -v/--verbose is set
326+
334327 int c;
335328
336329 // keep going while there are args left to handle
@@ -353,7 +346,7 @@ options_t::options_t(int argc, char *argv[]) : options_t()
353346 create = true ;
354347 break ;
355348 case ' v' :
356- verbose = true ;
349+ help_verbose = true ;
357350 break ;
358351 case ' s' :
359352 slim = true ;
@@ -472,21 +465,21 @@ options_t::options_t(int argc, char *argv[]) : options_t()
472465 extra_attributes = true ;
473466 break ;
474467 case ' k' :
475- if (hstore_mode != HSTORE_NONE ) {
468+ if (hstore_mode != hstore_column::none ) {
476469 throw std::runtime_error{" You can not specify both --hstore "
477470 " (-k) and --hstore-all (-j)\n " };
478471 }
479- hstore_mode = HSTORE_NORM ;
472+ hstore_mode = hstore_column::norm ;
480473 break ;
481474 case 208 :
482475 hstore_match_only = true ;
483476 break ;
484477 case ' j' :
485- if (hstore_mode != HSTORE_NONE ) {
478+ if (hstore_mode != hstore_column::none ) {
486479 throw std::runtime_error{" You can not specify both --hstore "
487480 " (-k) and --hstore-all (-j)\n " };
488481 }
489- hstore_mode = HSTORE_ALL ;
482+ hstore_mode = hstore_column::all ;
490483 break ;
491484 case ' z' :
492485 hstore_columns.emplace_back (optarg);
@@ -559,7 +552,7 @@ options_t::options_t(int argc, char *argv[]) : options_t()
559552
560553 // they were looking for usage info
561554 if (long_usage_bool) {
562- long_usage (argv[0 ], verbose );
555+ long_usage (argv[0 ], help_verbose );
563556 return ;
564557 }
565558
@@ -581,11 +574,9 @@ options_t::options_t(int argc, char *argv[]) : options_t()
581574 check_options ();
582575
583576 if (pass_prompt) {
584- char *prompt = simple_prompt (" Password:" , 100 , 0 );
585- if (prompt == nullptr ) {
586- database_options.password = boost::none;
587- } else {
588- database_options.password = std::string (prompt);
577+ char const *prompt = simple_prompt (" Password:" , 100 , 0 );
578+ if (prompt != nullptr ) {
579+ database_options.password = prompt;
589580 }
590581 }
591582}
@@ -605,15 +596,15 @@ void options_t::check_options()
605596 throw std::runtime_error{" --drop only makes sense with --slim.\n " };
606597 }
607598
608- if (hstore_mode == HSTORE_NONE && hstore_columns.empty () &&
599+ if (hstore_mode == hstore_column::none && hstore_columns.empty () &&
609600 hstore_match_only) {
610601 fprintf (stderr,
611602 " Warning: --hstore-match-only only makes sense with --hstore, "
612603 " --hstore-all, or --hstore-column; ignored.\n " );
613604 hstore_match_only = false ;
614605 }
615606
616- if (enable_hstore_index && hstore_mode == HSTORE_NONE &&
607+ if (enable_hstore_index && hstore_mode == hstore_column::none &&
617608 hstore_columns.empty ()) {
618609 fprintf (stderr, " Warning: --hstore-add-index only makes sense with "
619610 " hstore enabled.\n " );
0 commit comments