[GRASS-dev] d.redraw -> g.parser

Glynn Clements glynn at gclements.plus.com
Mon Nov 13 03:48:56 EST 2006


Hamish wrote:

> > The GUI dialog should only be generated if you don't pass any
> > arguments but the program has at least one required argument.
> > 
> > However, currently it's up to the module to implement this. Modules
> > which can be run without arguments should skip calling G_parser() if
> > no arguments are given, e.g.:
> > 
> > 	if (argc > 1 && G_parser(argc, argv))
> > 		exit(1);
> > 
> > If necessary, this could be added to G_parser(); relying upon the
> > module to do it saves G_parser() from having to determine whether
> > there are any required arguments.
> > 
> > Apart from that, the only use for a --no-ui switch which I can see is
> > to force an error message (rather than a dialog) when one or more
> > arguments are required but none are given.
> > 
> > Or am I missing something?
> 
> I am talking about shell scripts that normally take no arguments:
> 
> d.redraw  (GUI + [Run] is not desired)

So you want the equivalent of the "argc > 1" check for scripts, right?

> > > Any problem with adding the --q flag to get the same effect?
> > 
> > --q is for the user. If the user doesn't use --q, they presumably want
> > their normal verbosity settings to be honoured.
> > 
> > > -#GUI is not very useful here, commented:
> > > -#if [ "$1" != "@ARGS_PARSED@" ] ; then
> > > -#  exec g.parser "$0" "$@"
> > > -#fi
> > > +#GUI is not very useful here,
> > > +if [ "$1" != "@ARGS_PARSED@" ] ; then
> > > +  exec g.parser "$0" "$@" --q
> > > +fi
> > 
> > If you want an error message instead of a GUI when no arguments are
> > given, you could use:
> > 
> > if [ "$1" != "@ARGS_PARSED@" ] ; then
> >   if [ "$#" = 0 ] ; then
> >     exec g.parser "$0" "$@" --q
> >   else
> >     exec g.parser "$0" "$@"
> >   fi
> > fi
> 
> I want the modules to run when no args are passed, but use G_parser()
> otherwise. so maybe just:
> 
>    if [ "$#" -gt 0 ] ; then
>      exec g.parser "$0" "$@"
>    fi

Probably. However, you would have to manually set any defaults.

With a C program, the code sets opt->answer first. If it skips
G_parser(), opt->answer will still be set, so the rest of the code
will work.

Maybe g.parser should have an extra switch to enable the "argc > 1"
check? Scripts which can be run without arguments would set it to
bypass the call to G_parser(), but any options with default answers
would still have the corresponding variables set.

> what's contained in "@ARGS_PARSED@"?

Nothing. It's a "marker" which indicates that the script is being
re-invoked from g.parser, so it shouldn't call g.parser again.

-- 
Glynn Clements <glynn at gclements.plus.com>




More information about the grass-dev mailing list