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

Hi,

currently d.redraw doesn't use the parser as it takes no options.

For man pages, etc it is nice to use it.

There is --ui to force the GUI in parser.c, but no --no-ui to avoid it.
And no enviro vars to control this either, AFAICT.

Any problem with adding the --q flag to get the same effect?

-#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

?

thanks,
Hamish

Hamish wrote:

currently d.redraw doesn't use the parser as it takes no options.

For man pages, etc it is nice to use it.

There is --ui to force the GUI in parser.c, but no --no-ui to avoid it.
And no enviro vars to control this either, AFAICT.

What would --no-ui achieve?

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?

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

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

Glynn Clements wrote:

Hamish wrote:
> currently d.redraw doesn't use the parser as it takes no options.
>
> For man pages, etc it is nice to use it.
>
> There is --ui to force the GUI in parser.c, but no --no-ui to avoid
> it. And no enviro vars to control this either, AFAICT.

What would --no-ui achieve?

the same as GRASS_UI_TERM=1

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)

v.build.all, v.convert.all, v.in.sites.all
(GUI+[Run] would be ok IF --ui was given [but must function without tcltk])

for the last three, --q is probably a good idea.

right now they bypass g.parser most of the time:
if [ $# -eq 0 ] || [ $1 = "-h" -o $1 = "help" -o $1 = "-help" -o $1 = "--help" ] ; then
  if [ "$1" != "@ARGS_PARSED@" ] ; then
     exec g.parser "$0" "$@"
  fi
fi

We could add '-o $1 = "--html-description"', xml, tcl, ui, --q, --v, to
that list, but it seems a bad solution. Removing that line and running
with no args,

G63> GRASS_UI_TERM=1 d.redraw
Programmer error: no flags or options

> 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

what's contained in "@ARGS_PARSED@"?

Hamish

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@gclements.plus.com>