@@ -115,6 +115,15 @@ static void store_properties(properties_t *properties, options_t const &options)
115115 properties->set_int (" db_format" , options.middle_database_format );
116116 properties->set_string (" output" , options.output_backend );
117117
118+ if (options.style .empty ()) {
119+ properties->set_string (" style" , " " );
120+ } else {
121+ properties->set_string (
122+ " style" ,
123+ boost::filesystem::absolute (boost::filesystem::path{options.style })
124+ .string ());
125+ }
126+
118127 properties->store ();
119128}
120129
@@ -261,6 +270,38 @@ static void check_output(properties_t const &properties, options_t *options)
261270 options->output_backend , output);
262271}
263272
273+ static void check_and_update_style_file (properties_t *properties,
274+ options_t *options)
275+ {
276+ auto const style_file_from_import = properties->get_string (" style" , " " );
277+
278+ if (options->style .empty ()) {
279+ log_info (" Using style file '{}' (same as on import)." ,
280+ style_file_from_import);
281+ options->style = style_file_from_import;
282+ return ;
283+ }
284+
285+ if (style_file_from_import.empty ()) {
286+ throw std::runtime_error{" Style file from import is empty!?" };
287+ }
288+
289+ const auto absolute_path =
290+ boost::filesystem::absolute (boost::filesystem::path{options->style })
291+ .string ();
292+
293+ if (absolute_path == style_file_from_import) {
294+ log_info (" Using style file '{}' (same as on import)." ,
295+ style_file_from_import);
296+ return ;
297+ }
298+
299+ log_info (" Using the style file you specified on the command line"
300+ " ('{}') instead of the one used on import ('{}')." ,
301+ absolute_path, style_file_from_import);
302+ properties->set_string (" style" , absolute_path, true );
303+ }
304+
264305// This is called in "append" mode to check that the command line options are
265306// compatible with the properties stored in the database.
266307static void check_and_update_properties (properties_t *properties,
@@ -272,6 +313,7 @@ static void check_and_update_properties(properties_t *properties,
272313 check_prefix (*properties, options);
273314 check_db_format (*properties, options);
274315 check_output (*properties, options);
316+ check_and_update_style_file (properties, options);
275317}
276318
277319// If we are in append mode and the middle nodes table isn't there, it probably
@@ -291,6 +333,20 @@ static void check_for_nodes_table(options_t const &options)
291333 }
292334}
293335
336+ static void check_and_set_style (options_t *options)
337+ {
338+ if (!options->style_set ) {
339+ if (options->output_backend == " flex" ||
340+ options->output_backend == " gazetteer" ) {
341+ throw std::runtime_error{" You have to set the config file "
342+ " with the -S|--style option." };
343+ }
344+ if (options->output_backend == " pgsql" ) {
345+ options->style = DEFAULT_STYLE;
346+ }
347+ }
348+ }
349+
294350int main (int argc, char *argv[])
295351{
296352 try {
@@ -317,6 +373,7 @@ int main(int argc, char *argv[])
317373 if (properties.load ()) {
318374 check_and_update_properties (&properties, &options);
319375 } else {
376+ check_and_set_style (&options);
320377 check_for_nodes_table (options);
321378 }
322379
@@ -334,6 +391,7 @@ int main(int argc, char *argv[])
334391 }
335392 }
336393 } else {
394+ check_and_set_style (&options);
337395 store_properties (&properties, options);
338396 auto const finfo = run (options);
339397 store_data_properties (&properties, finfo);
0 commit comments