diff --git a/apps/gdal_rasterize_lib.cpp b/apps/gdal_rasterize_lib.cpp index 32a49be83c27..6b6981438133 100644 --- a/apps/gdal_rasterize_lib.cpp +++ b/apps/gdal_rasterize_lib.cpp @@ -300,14 +300,17 @@ GDALRasterizeOptionsGetParser(GDALRasterizeOptions *psOptions, .action([psOptions](const std::string &) { psOptions->bCreateOutput = true; }); + // Written that way so that in library mode, users can still use the -q + // switch, even if it has no effect + argParser->add_quiet_argument( + psOptionsForBinary ? &(psOptionsForBinary->bQuiet) : nullptr); + if (psOptionsForBinary) { argParser->add_open_options_argument( psOptionsForBinary->aosOpenOptions); - argParser->add_quiet_argument(&psOptionsForBinary->bQuiet); - argParser->add_argument("src_datasource") .metavar("") .store_into(psOptionsForBinary->osSource)