## NAME

g.parser

## DESCRIPTION

The command provides full parser support for GRASS scripts.

## OPTIONS

The arguments are stored in environment variables, named GIS_FLAG_<name> for flags and GIS_OPT_<name> for options. For flags, the value will be "1" if the flag was given, and "0" otherwise.

    #!/bin/sh

    # g.parser demo script

    #%Module
    #%  description: g.parser test script
    #%End
    #%flag
    #%  key: f
    #%  description: a flag
    #%END
    #%option
    #% key: raster
    #% type: string
    #% gisprompt: old,cell,raster
    #% description: raster input map
    #% required : yes
    #%end
    #%option
    #% key: vector
    #% type: string
    #% gisprompt: old,vector,vector
    #% description: vector input map
    #% required : yes
    #%end
    #%option
    #% key: option1
    #% type: string
    #% description: an option
    #% required : yes
    #%end

    if [ "$1" != "@ARGS_PARSED@" ] ; then
      exec $GISBASE/etc/bin/cmd/g.parser "$0" "$@"
    fi

    #add your code here
    echo ""
    if [ $GIS_FLAG_f -eq 1 ] ; then
      echo "Flag -f set"
    else
      echo "Flag -f not set"
    fi

    #test if parameter present:
    if [ "$GIS_OPT_option1" != "(null)" ] ; then
      echo "Value of GIS_OPT_option1: '$GIS_OPT_option1'"
    fi

    echo "Value of GIS_OPT_raster: '$GIS_OPT_raster'"
    echo "Value of GIS_OPT_vect: '$GIS_OPT_vector'"

    #add your code here

The `test.sh` script will provide following help text:

    ./test.sh --help

    Description:
     g.parser test script

    Usage:
     test.sh [-f] option=name

    Flags:
      -f   a flag

    Parameters:
      option   an option

## NOTES

An option can be instructed to allow multiple inputs by adding the following line:

    #% multiple : yes

While this will only directly change the Usage section of the help screen, the option's environmental string may be easily parsed from within a script. For example, individual comma separated identities for an option named "input" can be parsed with the following Bash shell code:

    IFS=,
    for opt in $GIS_OPT_input ; do
    	... "$opt"
    done

## SEE ALSO

g.findfile

## AUTHOR

Glynn Clements

Last changed: $Date: 2004/11/05 11:28:18 $