Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of two boolean vars during comman line parsing #2111

Merged
merged 2 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/command-line-parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,6 @@ options_t parse_command_line(int argc, char *argv[])
break;
case 'S': // --style
options.style = optarg;
options.style_set = true;
break;
case 'i': // --tablespace-index
options.tblsmain_index = optarg;
Expand Down Expand Up @@ -647,7 +646,6 @@ options_t parse_command_line(int argc, char *argv[])
break;
case 'O': // --output
options.output_backend = optarg;
options.output_backend_set = true;
break;
case 'x': // --extra-attributes
options.extra_attributes = true;
Expand Down
5 changes: 1 addition & 4 deletions src/options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ struct options_t
/// File name to output expired tiles list to
std::string expire_tiles_filename{"dirty_tiles"};

std::string output_backend{"pgsql"};
std::string output_backend;
std::string input_format; ///< input file format (default: autodetect)

osmium::Box bbox;
Expand Down Expand Up @@ -162,9 +162,6 @@ struct options_t
bool parallel_indexing = true;
bool create = false;
bool pass_prompt = false;

bool output_backend_set = false;
bool style_set = false;
}; // struct options_t

#endif // OSM2PGSQL_OPTIONS_HPP
14 changes: 9 additions & 5 deletions src/osm2pgsql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ static void check_output(properties_t const &properties, options_t *options)
{
auto const output = properties.get_string("output", "pgsql");

if (!options->output_backend_set) {
if (options->output_backend.empty()) {
options->output_backend = output;
log_info("Using output '{}' (same as on import).", output);
return;
Expand Down Expand Up @@ -334,9 +334,13 @@ static void check_for_nodes_table(options_t const &options)
}
}

static void check_and_set_style(options_t *options)
static void set_option_defaults(options_t *options)
{
if (!options->style_set) {
if (options->output_backend.empty()) {
options->output_backend = "pgsql";
}

if (options->style.empty()) {
if (options->output_backend == "flex" ||
options->output_backend == "gazetteer") {
throw std::runtime_error{"You have to set the config file "
Expand Down Expand Up @@ -375,7 +379,7 @@ int main(int argc, char *argv[])
if (properties.load()) {
check_and_update_properties(&properties, &options);
} else {
check_and_set_style(&options);
set_option_defaults(&options);
check_for_nodes_table(options);
}

Expand All @@ -393,7 +397,7 @@ int main(int argc, char *argv[])
}
}
} else {
check_and_set_style(&options);
set_option_defaults(&options);
store_properties(&properties, options);
auto const finfo = run(options);
store_data_properties(&properties, finfo);
Expand Down
1 change: 1 addition & 0 deletions tests/common-options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class opt_t
public:
opt_t()
{
m_opt.output_backend = "pgsql";
m_opt.prefix = "osm2pgsql_test";
m_opt.style = OSM2PGSQLDATA_DIR "default.style";
m_opt.num_procs = 1;
Expand Down
5 changes: 3 additions & 2 deletions tests/test-options-projection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ TEST_CASE("Projection setup")
{
char const* const style_file = OSM2PGSQLDATA_DIR "default.style";

std::vector<char const *> option_params = {"osm2pgsql", "-S", style_file,
"--number-processes", "1"};
std::vector<char const *> option_params = {"osm2pgsql", "--output=pgsql",
"-S", style_file,
"--number-processes=1"};

std::string proj_name;
char const *srid = "";
Expand Down