OSGeo / gdal

GDAL is an open source MIT licensed translator library for raster and vector geospatial data formats.
https://gdal.org
Other
4.92k stars 2.56k forks source link

gdal_calc incorrectly reports requiring no arguments for the --debug option #11312

Open ughur-a opened 1 day ago

ughur-a commented 1 day ago

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

jratike80 commented 1 day ago

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.

ughur-a commented 1 day ago

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

jratike80 commented 1 day ago

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"
rouault commented 1 day ago

Interesting, --quiet is configured in the same way but gdal_calc --quiet does not complain.

--debug is handled by generic GDAL parsing argument code, before the rest of gdal_calc has a chance to see it