gdal_calc incorrectly reports requiring no arguments for the --debug option
What is the bug?
the help page gdal_calc lists a --debug option, but says that it requires no arguments. In reality however, it seems to require a int value passed - the more sensible options being 0, 1 (but true and false also work)
Steps to reproduce the issue
gdal_calc --debug
returns ERROR 1: --debug option given without debug level.
Passing --debug before another option results in a cryptic error message:
gdal_calc.bat --calc "A+B" --format SAGA --type Float32 -A foo --A_band 1 -B bar --B_band 1 --debug --outfile baz
returns: gdal_calc.py: error: argument --B_band: invalid int value: 'baz'
Versions and provenance
OS: Windows 11 GDAL version: GDAL 3.9.3, released 2024/10/07 (the newest available version) Source of the GDAL binary: OSGeo4W
Additional context
No response
In the beginning of this Python script I read
debug: bool = False
Thus, it requires a standard Python boolean value True or False, but a few other alternatives work as well https://www.w3schools.com/python/python_booleans.asp.
Yes, I've seen that as well. But from I've gathered the, the arguments to the function are not the raw arguments passed to the command line - rather, the command line arguments first get parsed by GDALArgumentParser (see here), and it then passes the result to the actual function. And I guess GDALArgumentParser is the one that expects ints
Interesting, --quiet is configured in the same way but gdal_calc --quiet does not complain.
parser.add_argument(
"--debug",
dest="debug",
action="store_true",
help="print debugging information",
)
parser.add_argument(
"--quiet",
dest="quiet",
action="store_true",
help="suppress progress messages"
Interesting, --quiet is configured in the same way but
gdal_calc --quietdoes not complain.
--debug is handled by generic GDAL parsing argument code, before the rest of gdal_calc has a chance to see it
Would the fix be to edit the documentation https://gdal.org/en/stable/programs/gdal_calc.html#cmdoption-debug to tell that what works is for example --debug on, and also edit the help text in https://github.com/OSGeo/gdal/blob/master/swig/python/gdal-utils/osgeo_utils/gdal_calc.py#L842?