Skip to content

Commit

Permalink
Clean up the way we do early returns after printing help text
Browse files Browse the repository at this point in the history
  • Loading branch information
joto committed Jan 31, 2021
1 parent 5f402c3 commit 0a54991
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ options_t::options_t(int argc, char *argv[]) : options_t()
{
// If there are no command line arguments at all, show help.
if (argc == 1) {
long_usage_bool = true;
m_print_help = true;
long_usage(argv[0], false);
return;
}
Expand Down Expand Up @@ -517,7 +517,7 @@ options_t::options_t(int argc, char *argv[]) : options_t()
}
break;
case 'h':
long_usage_bool = true;
m_print_help = true;
break;
case 'I':
parallel_indexing = false;
Expand Down Expand Up @@ -641,7 +641,7 @@ options_t::options_t(int argc, char *argv[]) : options_t()
} //end while

//they were looking for usage info
if (long_usage_bool) {
if (m_print_help) {
long_usage(argv[0], help_verbose);
return;
}
Expand Down
12 changes: 11 additions & 1 deletion src/options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ class options_t
*/
options_t(int argc, char *argv[]);

/**
* Return true if the main program should end directly after the option
* parsing. This is true when a help text was printed.
*/
bool early_return() const noexcept {
return m_print_help;
}

std::string prefix{"planet_osm"}; ///< prefix for table names
std::shared_ptr<reprojection> projection; ///< SRS of projection
bool append = false; ///< Append to existing data
Expand Down Expand Up @@ -141,7 +149,6 @@ class options_t
boost::optional<std::string> tag_transform_rel_mem_func{boost::none};

bool create = false;
bool long_usage_bool = false;
bool pass_prompt = false;

database_options_t database_options;
Expand All @@ -161,6 +168,9 @@ class options_t
uint8_t way_node_index_id_shift = 0;

private:

bool m_print_help = false;

/**
* Check input options for sanity
*/
Expand Down
2 changes: 1 addition & 1 deletion src/osm2pgsql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ int main(int argc, char *argv[])
log_info("osm2pgsql version {}", get_osm2pgsql_version());

options_t const options{argc, argv};
if (options.long_usage_bool) {
if (options.early_return()) {
return 0;
}

Expand Down

0 comments on commit 0a54991

Please sign in to comment.