Skip to content

Commit 461b077

Browse files
committed
Check more command line options for "compatibility"
Adds some additional checks of the command line options. Adds warnings for * options ignored when using "flex" output * options ignored when using "null" output * incompatible options setting the output projection The function `opt->get_name(false, true)` used here returns a string with all the (short and long) names of a command line option.
1 parent d6fedbd commit 461b077

1 file changed

Lines changed: 68 additions & 18 deletions

File tree

src/command-line-parser.cpp

Lines changed: 68 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -128,24 +128,46 @@ void print_version()
128128
#endif
129129
}
130130

131-
static void check_options(options_t *options)
131+
static void check_options_output_flex(CLI::App const &app)
132132
{
133-
if (options->append && options->create) {
134-
throw std::runtime_error{"--append and --create options can not be "
135-
"used at the same time!"};
136-
}
137-
138-
if (options->append && !options->slim) {
139-
throw std::runtime_error{"--append can only be used with slim mode!"};
133+
auto const ignored_options = app.get_options([](CLI::Option const *option) {
134+
return option->get_group() == "Pgsql output options" ||
135+
option->get_name() == "--tablespace-main-data" ||
136+
option->get_name() == "--tablespace-main-index";
137+
});
138+
139+
for (auto const *opt : ignored_options) {
140+
if (opt->count()) {
141+
log_warn("Ignoring option {} for 'flex' output",
142+
opt->get_name(false, true));
143+
}
140144
}
145+
}
141146

142-
if (options->droptemp && !options->slim) {
143-
throw std::runtime_error{"--drop only makes sense with --slim."};
147+
static void check_options_output_null(CLI::App const &app)
148+
{
149+
auto const ignored_options = app.get_options([](CLI::Option const *option) {
150+
return option->get_group() == "Pgsql output options" ||
151+
option->get_group() == "Expire options" ||
152+
option->get_name() == "--style" ||
153+
option->get_name() == "--disable-parallel-indexing" ||
154+
option->get_name() == "--number-processes";
155+
});
156+
157+
for (auto const *opt : ignored_options) {
158+
if (opt->count()) {
159+
log_warn("Ignoring option {} for 'null' output",
160+
opt->get_name(false, true));
161+
}
144162
}
163+
}
145164

146-
if (options->append && options->middle_database_format != 1) {
147-
throw std::runtime_error{
148-
"Do not use --middle-database-format with --append."};
165+
static void check_options_output_pgsql(CLI::App const &app, options_t *options)
166+
{
167+
if (app.count("--latlong") + app.count("--merc") + app.count("--proj") >
168+
1) {
169+
throw std::runtime_error{"You can only use one of --latlong, -l, "
170+
"--merc, -m, --proj, and -E"};
149171
}
150172

151173
if (options->hstore_mode == hstore_column::none &&
@@ -162,6 +184,27 @@ static void check_options(options_t *options)
162184
"ignored.");
163185
options->enable_hstore_index = false;
164186
}
187+
}
188+
189+
static void check_options(options_t *options)
190+
{
191+
if (options->append && options->create) {
192+
throw std::runtime_error{"--append and --create options can not be "
193+
"used at the same time!"};
194+
}
195+
196+
if (options->append && !options->slim) {
197+
throw std::runtime_error{"--append can only be used with slim mode!"};
198+
}
199+
200+
if (options->droptemp && !options->slim) {
201+
throw std::runtime_error{"--drop only makes sense with --slim."};
202+
}
203+
204+
if (options->append && options->middle_database_format != 1) {
205+
throw std::runtime_error{
206+
"Do not use --middle-database-format with --append."};
207+
}
165208

166209
if (options->cache < 0) {
167210
options->cache = 0;
@@ -202,11 +245,6 @@ static void check_options(options_t *options)
202245
"target SRS is not Mercator (EPSG:3857). Expire disabled!");
203246
options->expire_tiles_zoom = 0;
204247
}
205-
206-
if (options->output_backend == "gazetteer") {
207-
log_warn(
208-
"The 'gazetteer' output is deprecated and will soon be removed.");
209-
}
210248
}
211249

212250
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
@@ -646,6 +684,18 @@ options_t parse_command_line(int argc, char *argv[])
646684
return options;
647685
}
648686

687+
if (options.output_backend == "flex") {
688+
check_options_output_flex(app);
689+
} else if (options.output_backend == "gazetteer") {
690+
log_warn(
691+
"The 'gazetteer' output is deprecated and will soon be removed.");
692+
} else if (options.output_backend == "null") {
693+
check_options_output_null(app);
694+
} else if (options.output_backend == "pgsql" ||
695+
options.output_backend.empty()) {
696+
check_options_output_pgsql(app, &options);
697+
}
698+
649699
if (options.input_format == "auto") {
650700
options.input_format.clear();
651701
}

0 commit comments

Comments
 (0)