[GRASS-dev] G70 annoing error during the command parsing

Hi all!

I'm trying to write a grass7 add-ons, but I'm fighting with one
parameter that wont work... and I'm not able to understand where the
problem is...

the python code is:

{{{
#!/usr/bin/env python
# -- coding: utf-8 --
#%Module
#% description: Test
#% keywords: test
#% keywords: options
#% overwrite: yes
#%End
#%option
#% key: hdf
#% type: string
#% description: Name of the HDF file
#% required: yes
#%end
#%option
#% key: ychk
#% type: string
#% description: Name for the training values in the HDF
#% required: no
#%end
#%option
#% key: Kchk
#% type: string
#% description: Name for the training values in the HDF
#% required: no
#%end
from grass.script import parser

def main(opts, flgs):
    for k, v in opts.items():
        print "%s = %r" % (k, v)

if __name__ == "__main__":
    options, flags = parser()
    main(options, flags)
}}}

the Makefile is:

{{{
MODULE_TOPDIR = ../..
PGM=r.try
include $(MODULE_TOPDIR)/include/Make/Script.make
default: script
}}}

The script is working If I don't use the Kchk parameter:

{{{

r.try hdf=result.hdf ychk=y_chk

hdf = 'result.hdf'
Kchk = ''
ychk = 'y_chk'
}}}

otherwise it raise an error:

{{{

r.try hdf=result.hdf ychk=y_chk Kchk=K_chk

Description:
Test

Keywords:
test, options

Usage:
r.try hdf=string [ychk=string] [Kchk=string] [--overwrite]
   [--verbose] [--quiet]

Flags:
--o Allow output files to overwrite existing files
--v Verbose module output
--q Quiet module output

Parameters:
   hdf Name of the HDF file
  ychk Name for the training values in the HDF
  Kchk Name for the training values in the HDF

ERROR: Sorry <Kchk=K_chk> is not a valid option
}}}

Do you understand what I'm doing wrong? why is ychk working?
I'm using grass r57429

Best regards.

Pietro

Hi Pietro,

···

On Wed, Aug 7, 2013 at 1:39 PM, Pietro <peter.zamb@gmail.com> wrote:

Hi all!

I’m trying to write a grass7 add-ons, but I’m fighting with one
parameter that wont work… and I’m not able to understand where the
problem is…

the python code is:

{{{
ERROR: Sorry <Kchk=K_chk> is not a valid option
}}}

Do you understand what I’m doing wrong? why is ychk working?
I’m using grass r57429

It seems that uppercase letters are not allowed for option names, see is_option function in parser.c
http://grass.osgeo.org/programming7/parser_8c_source.html

I guess you have some reason to use uppercase letters but maybe it would still be better to use lowercase letters to avoid confusion in the future (not to start mixing camelCase and snake_case for example)?

Anna

On Wed, Aug 7, 2013 at 2:58 PM, Anna Petrášová <kratochanna@gmail.com> wrote:

On Wed, Aug 7, 2013 at 1:39 PM, Pietro <peter.zamb@gmail.com> wrote:

I'm trying to write a grass7 add-ons, but I'm fighting with one
parameter that wont work... and I'm not able to understand where the
problem is...

the python code is:

{{{
ERROR: Sorry <Kchk=K_chk> is not a valid option
}}}

Do you understand what I'm doing wrong? why is ychk working?
I'm using grass r57429

It seems that uppercase letters are not allowed for option names, see
is_option function in parser.c
http://grass.osgeo.org/programming7/parser_8c_source.html

I guess you have some reason to use uppercase letters but maybe it would
still be better to use lowercase letters to avoid confusion in the future
(not to start mixing camelCase and snake_case for example)?

Wow Anna, thank you! I didn't realize that the upper-case was the
problem! I will use the lower-case parameter.

Best regards!

Pietro