New --script flag was: Re: [GRASS-dev] how to display a
vector map for d.path in gis.m?
Glynn Clements
glynn at gclements.plus.com
Fri Feb 2 01:08:04 EST 2007
Michael Barton wrote:
> >>> Hmm; it might be useful to have some means of automatically generating
> >>> the corresponding g.parser description for a given command. There are
> >>> probably quite a few scripts whose options are (almost) identical to
> >>> an existing command. I'll look into it.
> >>>
> >>
> >> I've extended G_parser() with a --script flag, which writes out a
> >> script with g.parser syntax to mimic the behaviour of the module. This
> >> shoud make it easier to write scripts which mimic an existing command.
> >>
> > Really cool! Thanks, Glynn.
>
> Could you explain how this works a bit more? It sounds cool, but I don't
> quite understand how it might be used.
Taking d.path as an example, you would first run e.g.:
d.path --script > d.path.sh
This will generate a script which contains the g.parser boilerplate
which would be required for a script with the same set of options as
d.path.
To this script, you would append something like the following:
cmd=d.path
if [ "$GIS_FLAG_G" != 0 ] ; then cmd="$cmd -g" ; fi
if [ "$GIS_OPT_MAP" != "" ] ; then cmd="$cmd map=$GIS_OPT_MAP" ; fi
if [ "$GIS_OPT_TYPE" != "" ] ; then cmd="$cmd type=$GIS_OPT_TYPE" ; fi
if [ "$GIS_OPT_ALAYER" != "" ] ; then cmd="$cmd alayer=$GIS_OPT_ALAYER" ; fi
if [ "$GIS_OPT_NLAYER" != "" ] ; then cmd="$cmd nlayer=$GIS_OPT_NLAYER" ; fi
if [ "$GIS_OPT_AFCOL" != "" ] ; then cmd="$cmd afcol=$GIS_OPT_AFCOL" ; fi
if [ "$GIS_OPT_ABCOL" != "" ] ; then cmd="$cmd abcol=$GIS_OPT_ABCOL" ; fi
if [ "$GIS_OPT_NCOL" != "" ] ; then cmd="$cmd ncol=$GIS_OPT_NCOL" ; fi
if [ "$GIS_OPT_COLOR" != "" ] ; then cmd="$cmd color=$GIS_OPT_COLOR" ; fi
if [ "$GIS_OPT_HCOLOR" != "" ] ; then cmd="$cmd hcolor=$GIS_OPT_HCOLOR" ; fi
if [ "$GIS_OPT_BGCOLOR" != "" ] ; then cmd="$cmd bgcolor=$GIS_OPT_BGCOLOR" ; fi
d.vect "$GIS_OPT_MAP"
exec $cmd
This script should run "d.vect <map>", then run d.path with whatever
options were passed to the d.path.sh script.
Essentially, if you want to write a script which behaves like some
existing command, the --script option can be used to avoid having to
type out the g.parser boilerplate by hand.
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-dev
mailing list