1g.parser(1)                   Grass User's Manual                  g.parser(1)
2
3
4

NAME

6       g.parser
7

DESCRIPTION

9       The  g.parser  module  provides  full parser support for GRASS scripts,
10       including an auto-generated GUI interface, help page template, and com‐
11       mand line option checking. In this way a simple script can very quickly
12       be made into a full-fledged GRASS module.
13

OPTIONS

15       After parsing the arguments are stored in environment variables for use
16       in  your  scripts.  These variables are named "GIS_FLAG_" for flags and
17       "GIS_OPT_" for options.  The names of variables are converted to  upper
18       case. For example if an option with key input was defined in the script
19       header, the value will be available in variable GIS_OPT_INPUT  and  the
20       value of flag with key f will be available in variable GIS_FLAG_F.
21
22       For  flags, the value will be "1" if the flag was given, and "0" other‐
23       wise.
24
25       Typical header definitions are as follows:
26       #%Module
27       #%  description: g.parser test script
28       #%End
29       #%flag
30       #%  key: f
31       #%  description: A flag
32       #%end
33       #%option
34       #%  key: raster
35       #%  type: string
36       #%  gisprompt: old,cell,raster
37       #%  description: Raster input map
38       #%  required : yes
39       #%end
40
41

NOTES

43       An option can be instructed to allow multiple inputs by adding the fol‐
44       lowing line:
45       While this will only directly change the Usage section of the help
46       screen,  the  option's  environmental  string may be easily parsed from
47       within
48       a script. For example, individual comma  separated  identities  for  an
49       option
50       named "input" can be parsed with the following Bash shell code:
51
52       for opt in $GIS_OPT_INPUT ; do
53           ... "$opt"
54       done
55
56
57       A  "guisection"  field  may be added to each option and flag to specify
58       that the options should appear in multiple tabs in  the  auto-generated
59       GUI.  Any options without a guisection field go into the "Options" tab.
60       For example:
61       would put that option in a tab named tabname.
62
63       A "<tt>key_desc" field may be added to each option to specify the text
64       that appears in the module's usage help section. For example:
65
66       added to an input option would create the usage summary
67       <tt>[input=filename].
68

TRANSLATION

70       g.parser provides some support for translating the options of scripts.
71       If called with the -t switch before the script filename like this
72
73       g.parser -t somescriptfile
74        g.parser will print the text of the translatable  options  to  stdout,
75       one  per line, and exit. This is for internal use within the build sys‐
76       tem to prepare GRASS scripts for translation.
77

EXAMPLES

79   Example code for SHELL
80
81       #!/bin/sh
82       # g.parser demo script for shell programing
83       #%Module
84       #%  description: g.parser test script
85       #%End
86       #%flag
87       #%  key: f
88       #%  description: A flag
89       #%END
90       #%option
91       #% key: raster
92       #% type: string
93       #% gisprompt: old,cell,raster
94       #% description: Raster input map
95       #% required : yes
96       #%end
97       #%option
98       #% key: vector
99       #% type: string
100       #% gisprompt: old,vector,vector
101       #% description: Vector input map
102       #% required : yes
103       #%end
104       #%option
105       #% key: option1
106       #% type: string
107       #% description: An option
108       #% required : no
109       #%end
110       if [ -z "$GISBASE" ] ; then
111           echo "You must be in GRASS GIS to run this program." 1>&2
112           exit 1
113       fi
114       if [ "$1" != "@ARGS_PARSED@" ] ; then
115         exec g.parser "$0" "$@"
116       fi
117       #add your code here
118       echo ""
119       if [ $GIS_FLAG_F -eq 1 ] ; then
120         echo "Flag -f set"
121       else
122         echo "Flag -f not set"
123       fi
124       #test if parameter present:
125       if [ -n "$GIS_OPT_OPTION1" ] ; then
126         echo "Value of GIS_OPT_OPTION1: '$GIS_OPT_OPTION1'"
127       fi
128       echo "Value of GIS_OPT_RASTER: '$GIS_OPT_RASTER'"
129       echo "Value of GIS_OPT_VECTOR: '$GIS_OPT_VECTOR'"
130       #add your code here
131
132
133       The test.sh script will provide following help text:
134
135
136       Description:
137        g.parser test script
138
139       Usage:
140        test.sh [-f] option=name
141
142       Flags:
143         -f   A flag
144
145       Parameters:
146         option   an option
147
148

SEE ALSO

150        d.ask, d.menu, g.ask, g.filename, g.findfile, g.tempfile, and the SUB‐
151       MITTING_SCRIPTS file in the GRASS source code.
152

AUTHOR

154       Glynn Clements
155
156       Last changed: $Date: 2007/06/11 03:24:59 $
157
158
159
160GRASS 6.2.2                                                        g.parser(1)
Impressum