Skip to content

Commit 0a54991

Browse files
committed
Clean up the way we do early returns after printing help text
1 parent 5f402c3 commit 0a54991

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

src/options.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ options_t::options_t(int argc, char *argv[]) : options_t()
341341
{
342342
// If there are no command line arguments at all, show help.
343343
if (argc == 1) {
344-
long_usage_bool = true;
344+
m_print_help = true;
345345
long_usage(argv[0], false);
346346
return;
347347
}
@@ -517,7 +517,7 @@ options_t::options_t(int argc, char *argv[]) : options_t()
517517
}
518518
break;
519519
case 'h':
520-
long_usage_bool = true;
520+
m_print_help = true;
521521
break;
522522
case 'I':
523523
parallel_indexing = false;
@@ -641,7 +641,7 @@ options_t::options_t(int argc, char *argv[]) : options_t()
641641
} //end while
642642

643643
//they were looking for usage info
644-
if (long_usage_bool) {
644+
if (m_print_help) {
645645
long_usage(argv[0], help_verbose);
646646
return;
647647
}

src/options.hpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ class options_t
6161
*/
6262
options_t(int argc, char *argv[]);
6363

64+
/**
65+
* Return true if the main program should end directly after the option
66+
* parsing. This is true when a help text was printed.
67+
*/
68+
bool early_return() const noexcept {
69+
return m_print_help;
70+
}
71+
6472
std::string prefix{"planet_osm"}; ///< prefix for table names
6573
std::shared_ptr<reprojection> projection; ///< SRS of projection
6674
bool append = false; ///< Append to existing data
@@ -141,7 +149,6 @@ class options_t
141149
boost::optional<std::string> tag_transform_rel_mem_func{boost::none};
142150

143151
bool create = false;
144-
bool long_usage_bool = false;
145152
bool pass_prompt = false;
146153

147154
database_options_t database_options;
@@ -161,6 +168,9 @@ class options_t
161168
uint8_t way_node_index_id_shift = 0;
162169

163170
private:
171+
172+
bool m_print_help = false;
173+
164174
/**
165175
* Check input options for sanity
166176
*/

src/osm2pgsql.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ int main(int argc, char *argv[])
6161
log_info("osm2pgsql version {}", get_osm2pgsql_version());
6262

6363
options_t const options{argc, argv};
64-
if (options.long_usage_bool) {
64+
if (options.early_return()) {
6565
return 0;
6666
}
6767

0 commit comments

Comments
 (0)