2727#endif
2828
2929#include < algorithm>
30+ #include < array>
3031#include < cstdio>
3132#include < cstring>
3233#include < stdexcept>
@@ -128,24 +129,65 @@ void print_version()
128129#endif
129130}
130131
131- static void check_options ( options_t *options )
132+ static void check_options_non_slim (CLI::App const &app )
132133{
133- if (options->append && options->create ) {
134- throw std::runtime_error{" --append and --create options can not be "
135- " used at the same time!" };
134+ std::array<std::string, 7 > const slim_options = {
135+ " --flat-nodes" ,
136+ " --middle-database-format" ,
137+ " --middle-schema" ,
138+ " --middle-with-nodes" ,
139+ " --middle-way-node-index-id-shift" ,
140+ " --tablespace-slim-data" ,
141+ " --tablespace-slim-index" };
142+
143+ for (auto const &opt : slim_options) {
144+ if (app.count (opt) > 0 ) {
145+ log_warn (" Ignoring option {}. Can only be used in --slim mode." ,
146+ app.get_option (opt)->get_name (false , true ));
147+ }
136148 }
149+ }
137150
138- if (options->append && !options->slim ) {
139- throw std::runtime_error{" --append can only be used with slim mode!" };
151+ static void check_options_output_flex (CLI::App const &app)
152+ {
153+ auto const ignored_options = app.get_options ([](CLI::Option const *option) {
154+ return option->get_group () == " Pgsql output options" ||
155+ option->get_name () == " --tablespace-main-data" ||
156+ option->get_name () == " --tablespace-main-index" ;
157+ });
158+
159+ for (auto const *opt : ignored_options) {
160+ if (opt->count ()) {
161+ log_warn (" Ignoring option {} for 'flex' output" ,
162+ opt->get_name (false , true ));
163+ }
140164 }
165+ }
141166
142- if (options->droptemp && !options->slim ) {
143- throw std::runtime_error{" --drop only makes sense with --slim." };
167+ static void check_options_output_null (CLI::App const &app)
168+ {
169+ auto const ignored_options = app.get_options ([](CLI::Option const *option) {
170+ return option->get_group () == " Pgsql output options" ||
171+ option->get_group () == " Expire options" ||
172+ option->get_name () == " --style" ||
173+ option->get_name () == " --disable-parallel-indexing" ||
174+ option->get_name () == " --number-processes" ;
175+ });
176+
177+ for (auto const *opt : ignored_options) {
178+ if (opt->count ()) {
179+ log_warn (" Ignoring option {} for 'null' output" ,
180+ opt->get_name (false , true ));
181+ }
144182 }
183+ }
145184
146- if (options->append && options->middle_database_format != 1 ) {
147- throw std::runtime_error{
148- " Do not use --middle-database-format with --append." };
185+ static void check_options_output_pgsql (CLI::App const &app, options_t *options)
186+ {
187+ if (app.count (" --latlong" ) + app.count (" --merc" ) + app.count (" --proj" ) >
188+ 1 ) {
189+ throw std::runtime_error{" You can only use one of --latlong, -l, "
190+ " --merc, -m, --proj, and -E" };
149191 }
150192
151193 if (options->hstore_mode == hstore_column::none &&
@@ -162,6 +204,27 @@ static void check_options(options_t *options)
162204 " ignored." );
163205 options->enable_hstore_index = false ;
164206 }
207+ }
208+
209+ static void check_options (options_t *options)
210+ {
211+ if (options->append && options->create ) {
212+ throw std::runtime_error{" --append and --create options can not be "
213+ " used at the same time!" };
214+ }
215+
216+ if (options->append && !options->slim ) {
217+ throw std::runtime_error{" --append can only be used with slim mode!" };
218+ }
219+
220+ if (options->droptemp && !options->slim ) {
221+ throw std::runtime_error{" --drop only makes sense with --slim." };
222+ }
223+
224+ if (options->append && options->middle_database_format != 1 ) {
225+ throw std::runtime_error{
226+ " Do not use --middle-database-format with --append." };
227+ }
165228
166229 if (options->cache < 0 ) {
167230 options->cache = 0 ;
@@ -178,12 +241,11 @@ static void check_options(options_t *options)
178241 " processing a lot." );
179242 }
180243 }
244+ }
181245
182- if (!options->slim && !options->flat_node_file .empty ()) {
183- log_warn (" Ignoring --flat-nodes/-F setting in non-slim mode" );
184- }
185-
186- // zoom level 31 is the technical limit because we use 32-bit integers for the x and y index of a tile ID
246+ static void check_options_expire (options_t *options) {
247+ // Zoom level 31 is the technical limit because we use 32-bit integers for
248+ // the x and y index of a tile ID.
187249 if (options->expire_tiles_zoom_min > 31 ) {
188250 options->expire_tiles_zoom_min = 31 ;
189251 log_warn (" Minimum zoom level for tile expiry is too "
@@ -202,11 +264,6 @@ static void check_options(options_t *options)
202264 " target SRS is not Mercator (EPSG:3857). Expire disabled!" );
203265 options->expire_tiles_zoom = 0 ;
204266 }
205-
206- if (options->output_backend == " gazetteer" ) {
207- log_warn (
208- " The 'gazetteer' output is deprecated and will soon be removed." );
209- }
210267}
211268
212269// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
@@ -646,6 +703,22 @@ options_t parse_command_line(int argc, char *argv[])
646703 return options;
647704 }
648705
706+ if (!options.slim ) {
707+ check_options_non_slim (app);
708+ }
709+
710+ if (options.output_backend == " flex" ) {
711+ check_options_output_flex (app);
712+ } else if (options.output_backend == " gazetteer" ) {
713+ log_warn (
714+ " The 'gazetteer' output is deprecated and will soon be removed." );
715+ } else if (options.output_backend == " null" ) {
716+ check_options_output_null (app);
717+ } else if (options.output_backend == " pgsql" ||
718+ options.output_backend .empty ()) {
719+ check_options_output_pgsql (app, &options);
720+ }
721+
649722 if (options.input_format == " auto" ) {
650723 options.input_format .clear ();
651724 }
@@ -686,6 +759,8 @@ options_t parse_command_line(int argc, char *argv[])
686759 options.projection = reprojection::create_projection (PROJ_SPHERE_MERC);
687760 }
688761
762+ check_options_expire (&options);
763+
689764 check_options (&options);
690765
691766 options.connection_params = app.connection_params ();
0 commit comments