Skip to content

Commit 8e0d177

Browse files
authored
Merge pull request #12737 from rouault/progress_by_default
gdal cli: turn on progress bar by default, and text mode for gdal raster/vector info and gdal vsi list
2 parents 5c7584b + ed003be commit 8e0d177

29 files changed

+131
-54
lines changed

MIGRATION_GUIDE.TXT

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ MIGRATION GUIDE FROM GDAL 3.11 to GDAL 3.12
99
will be definitely removed in 3.13.
1010
* Furthermore, sub-command "set-type" of "gdal vector geom" is renamed as
1111
"set-geom-type" and also placed under "gdal vector".
12+
* Progress bar is emitted to stdout by default unless --quiet/-q is specified.
13+
* For gdal raster info, gdal vector info and gdal vsi list, --format=text is
14+
now the default when those utilities are invoked from the command line.
15+
When they are invoked from the API, the default is still JSON.
1216

1317
- The raw file capabilities (VRTRawRasterBand) of the VRT raster driver have
1418
been limited by default for security reasons. Consult

apps/gdalalg_dataset_identify.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ GDALDatasetIdentifyAlgorithm::GDALDatasetIdentifyAlgorithm()
3434
.SetRequired();
3535
SetAutoCompleteFunctionForFilename(arg, 0);
3636

37-
AddOutputFormatArg(&m_format).SetDefault("json").SetChoices("json", "text");
37+
AddOutputFormatArg(&m_format).SetChoices("json", "text");
3838

3939
AddArg("recursive", 'r', _("Recursively scan files/folders for datasets"),
4040
&m_recursive);
@@ -88,6 +88,12 @@ bool GDALDatasetIdentifyAlgorithm::Process(const char *pszTarget,
8888
void *pProgressData)
8989

9090
{
91+
if (IsCalledFromCommandLine())
92+
pfnProgress = nullptr;
93+
94+
if (m_format.empty())
95+
m_format = IsCalledFromCommandLine() ? "text" : "json";
96+
9197
GDALDriverH hDriver = nullptr;
9298
{
9399
CPLErrorStateBackuper oBackuper(CPLQuietErrorHandler);
@@ -163,6 +169,9 @@ bool GDALDatasetIdentifyAlgorithm::Process(const char *pszTarget,
163169
bool GDALDatasetIdentifyAlgorithm::RunImpl(GDALProgressFunc pfnProgress,
164170
void *pProgressData)
165171
{
172+
if (m_format.empty())
173+
m_format = IsCalledFromCommandLine() ? "text" : "json";
174+
166175
if (m_format == "json")
167176
m_oWriter.StartArray();
168177
int i = 0;

apps/gdalalg_dataset_identify.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class GDALDatasetIdentifyAlgorithm final : public GDALAlgorithm
3636

3737
private:
3838
std::vector<std::string> m_filename{};
39-
std::string m_format = "json";
39+
std::string m_format{};
4040
CPLJSonStreamingWriter m_oWriter;
4141
std::string m_output{};
4242
bool m_recursive = false;

apps/gdalalg_pipeline.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ bool GDALPipelineAlgorithm::ParseCommandLineArguments(
458458
if (arg.find("--pipeline") == 0)
459459
return GDALAlgorithm::ParseCommandLineArguments(args);
460460

461-
// gdal pipeline [--progress] "read poly.gpkg ..."
461+
// gdal pipeline [--quiet] "read poly.gpkg ..."
462462
if (arg.find("read ") == 0)
463463
return GDALAlgorithm::ParseCommandLineArguments(args);
464464
}
@@ -489,6 +489,12 @@ bool GDALPipelineAlgorithm::ParseCommandLineArguments(
489489
m_progressBarRequested = true;
490490
continue;
491491
}
492+
if (arg == "--quiet")
493+
{
494+
m_quiet = true;
495+
m_progressBarRequested = false;
496+
continue;
497+
}
492498

493499
if (IsCalledFromCommandLine() && (arg == "-h" || arg == "--help"))
494500
{

apps/gdalalg_raster_info.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
GDALRasterInfoAlgorithm::GDALRasterInfoAlgorithm(bool openForMixedRasterVector)
3030
: GDALAlgorithm(NAME, DESCRIPTION, HELP_URL)
3131
{
32-
AddOutputFormatArg(&m_format).SetDefault("json").SetChoices("json", "text");
32+
AddOutputFormatArg(&m_format).SetChoices("json", "text");
3333
AddArg("min-max", 0, _("Compute minimum and maximum value"), &m_minMax)
3434
.AddAlias("mm");
3535
AddArg("stats", 0, _("Retrieve or compute statistics, using all pixels"),
@@ -98,6 +98,9 @@ bool GDALRasterInfoAlgorithm::RunImpl(GDALProgressFunc, void *)
9898
{
9999
CPLAssert(m_dataset.GetDatasetRef());
100100

101+
if (m_format.empty())
102+
m_format = IsCalledFromCommandLine() ? "text" : "json";
103+
101104
CPLStringList aosOptions;
102105
if (m_format == "json")
103106
aosOptions.AddString("-json");

apps/gdalalg_raster_pipeline.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ bool GDALRasterPipelineAlgorithm::ParseCommandLineArguments(
237237
if (arg.find("--pipeline") == 0)
238238
return GDALAlgorithm::ParseCommandLineArguments(args);
239239

240-
// gdal raster pipeline [--progress] "read in.tif ..."
240+
// gdal raster pipeline [--quiet] "read in.tif ..."
241241
if (arg.find("read ") == 0)
242242
return GDALAlgorithm::ParseCommandLineArguments(args);
243243
}
@@ -266,6 +266,12 @@ bool GDALRasterPipelineAlgorithm::ParseCommandLineArguments(
266266
m_progressBarRequested = true;
267267
continue;
268268
}
269+
if (arg == "--quiet")
270+
{
271+
m_quiet = true;
272+
m_progressBarRequested = false;
273+
continue;
274+
}
269275

270276
if (IsCalledFromCommandLine() && (arg == "-h" || arg == "--help"))
271277
{

apps/gdalalg_vector_info.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
GDALVectorInfoAlgorithm::GDALVectorInfoAlgorithm()
3030
: GDALAlgorithm(NAME, DESCRIPTION, HELP_URL)
3131
{
32-
AddOutputFormatArg(&m_format).SetDefault("json").SetChoices("json", "text");
32+
AddOutputFormatArg(&m_format).SetChoices("json", "text");
3333
AddOpenOptionsArg(&m_openOptions);
3434
AddInputFormatsArg(&m_inputFormats)
3535
.AddMetadataItem(GAAMDI_REQUIRED_CAPABILITIES, {GDAL_DCAP_VECTOR});
@@ -89,6 +89,9 @@ bool GDALVectorInfoAlgorithm::RunImpl(GDALProgressFunc, void *)
8989
{
9090
CPLAssert(m_dataset.GetDatasetRef());
9191

92+
if (m_format.empty())
93+
m_format = IsCalledFromCommandLine() ? "text" : "json";
94+
9295
CPLStringList aosOptions;
9396

9497
aosOptions.AddString("--cli");

apps/gdalalg_vector_pipeline.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ bool GDALVectorPipelineAlgorithm::ParseCommandLineArguments(
187187
if (arg.find("--pipeline") == 0)
188188
return GDALAlgorithm::ParseCommandLineArguments(args);
189189

190-
// gdal vector pipeline [--progress] "read poly.gpkg ..."
190+
// gdal vector pipeline [--quiet] "read poly.gpkg ..."
191191
if (arg.find("read ") == 0)
192192
return GDALAlgorithm::ParseCommandLineArguments(args);
193193
}
@@ -216,6 +216,12 @@ bool GDALVectorPipelineAlgorithm::ParseCommandLineArguments(
216216
m_progressBarRequested = true;
217217
continue;
218218
}
219+
if (arg == "--quiet")
220+
{
221+
m_quiet = true;
222+
m_progressBarRequested = false;
223+
continue;
224+
}
219225

220226
if (IsCalledFromCommandLine() && (arg == "-h" || arg == "--help"))
221227
{

apps/gdalalg_vector_sql.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ GDALVectorSQLAlgorithm::GDALVectorSQLAlgorithm(bool standaloneStep)
5959
AddArg("output-layer", standaloneStep ? 0 : 'l', _("Output layer name(s)"),
6060
&m_outputLayer);
6161
AddArg("dialect", 0, _("SQL dialect (e.g. OGRSQL, SQLITE)"), &m_dialect);
62-
AddArg("quiet", 'q', _("Quiet mode"), &m_quiet);
6362
}
6463

6564
/************************************************************************/

apps/gdalalg_vector_sql.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class GDALVectorSQLAlgorithm /* non final */
3939
std::vector<std::string> m_sql{};
4040
std::vector<std::string> m_outputLayer{};
4141
std::string m_dialect{};
42-
bool m_quiet = false;
4342
};
4443

4544
/************************************************************************/

0 commit comments

Comments
 (0)