[GRASS-SVN] r41119 - grass/trunk/general/g.parser
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Feb 19 06:49:21 EST 2010
Author: glynn
Date: 2010-02-19 06:49:20 -0500 (Fri, 19 Feb 2010)
New Revision: 41119
Modified:
grass/trunk/general/g.parser/g.parser.html
grass/trunk/general/g.parser/main.c
Log:
Document -s flag
Modified: grass/trunk/general/g.parser/g.parser.html
===================================================================
--- grass/trunk/general/g.parser/g.parser.html 2010-02-19 11:39:19 UTC (rev 41118)
+++ grass/trunk/general/g.parser/g.parser.html 2010-02-19 11:49:20 UTC (rev 41119)
@@ -13,7 +13,18 @@
<h2>NAME</h2>
<em><b>g.parser</b></em>
+<h2>SYNOPSIS</h2>
+<b>g.parser help</b><br>
+<b>g.parser</b> [-<b>s</b>] [-<b>t</b>] <em>filename</em> [<em>argument</em>,...]
+<h3>Flags:</h3>
+<DL>
+<DT><b>-t</b></DT>
+<DD>Print strings for translation</DD>
+<DT><b>-s</b></DT>
+<DD>Write option values to stdout instead of reinvoking script</DD>
+</DL>
+
<h2>DESCRIPTION</h2>
The <em>g.parser</em> module provides full parser support for GRASS
@@ -24,18 +35,29 @@
<h2>OPTIONS</h2>
-After parsing the arguments are stored in environment variables for
-use in your scripts. These variables are named "GIS_FLAG_<NAME>"
-for flags and "GIS_OPT_<NAME>" for options. The names of
-variables are converted to upper case. For example if an option with
-key <b>input</b> was defined in the script header, the value will be
-available in variable <b>GIS_OPT_INPUT</b> and the value of flag with
-key <b>f</b> will be available in variable <b>GIS_FLAG_F</b>.
+Unless the <b>-s</b> switch is used, the arguments are stored in
+environment variables for use in your scripts. These variables are
+named "GIS_FLAG_<NAME>" for flags and "GIS_OPT_<NAME>" for
+options. The names of variables are converted to upper case. For
+example if an option with key <b>input</b> was defined in the script
+header, the value will be available in variable <b>GIS_OPT_INPUT</b>
+and the value of flag with key <b>f</b> will be available in variable
+<b>GIS_FLAG_F</b>.
<p>
For flags, the value will be "1" if the flag was given, and "0" otherwise.
<p>
+If the <b>-s</b> switch is used, the options and flags are written to
+stdout in the form <em>opt_<name>=<value></em> and
+<em>flag_<name>=<value></em>, preceded by the string
+<b>@ARGS_PARSED@</b>. If this string doesn't appear as the first line
+of stdout, it indicates that the script was invoked with a switch such
+as <b>--html-description</b>. In this case, the data written by
+<em>g.parser</em> to stdout should be copied to the script's stdout
+verbatim.
+
+<p>
Typical header definitions are as follows:
<div class="code"><pre>
@@ -254,19 +276,23 @@
import grass.script as grass
def main():
+ flag_f = flags['f']
+ option1 = options['option1']
+ raster = options['raster']
+ vector = options['vector']
#### add your code here ####
- if flags['f']:
+ if flag_f:
print "Flag -f set"
else:
print "Flag -f not set"
# test if parameter present:
- if options['option1']:
- print "Value of GIS_OPT_OPTION1: '%s'" % options['option1']
+ if option1:
+ print "Value of option1= option: '%s'" % option1
- print "Value of GIS_OPT_RASTER: '%s'" % options['raster']
- print "Value of GIS_OPT_VECTOR: '%s'" % options['vector']
+ print "Value of raster= option: '%s'" % raster
+ print "Value of vector= option: '%s'" % vector
#### end of your code ####
@@ -274,7 +300,7 @@
if __name__ == "__main__":
options, flags = grass.parser()
- sys.exit(main())
+ main()
</pre></div>
The <tt>test.py</tt> script will provide following help text:
Modified: grass/trunk/general/g.parser/main.c
===================================================================
--- grass/trunk/general/g.parser/main.c 2010-02-19 11:39:19 UTC (rev 41118)
+++ grass/trunk/general/g.parser/main.c 2010-02-19 11:49:20 UTC (rev 41119)
@@ -395,7 +395,7 @@
if ((argc < 2) || ((strcmp(argv[1], "help") == 0) ||
(strcmp(argv[1], "-help") == 0) ||
(strcmp(argv[1], "--help") == 0))) {
- fprintf(stderr, "Usage: %s [-t] <filename> [<argument> ...]\n",
+ fprintf(stderr, "Usage: %s [-t] [-s] <filename> [<argument> ...]\n",
argv[0]);
return 1;
}
More information about the grass-commit
mailing list