summaryrefslogtreecommitdiff
path: root/man/man1/pmgetopt.1
blob: 03028615b8242560eb3e66917a5c6dc21f428b36 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
'\"! tbl | mmdoc
'\"macro stdmacro
.\"
.\" Copyright (c) 2014 Red Hat.
.\" 
.\" This program is free software; you can redistribute it and/or modify it
.\" under the terms of the GNU General Public License as published by the
.\" Free Software Foundation; either version 2 of the License, or (at your
.\" option) any later version.
.\" 
.\" This program is distributed in the hope that it will be useful, but
.\" WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
.\" or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
.\" for more details.
.\"
.TH PMGETOPT 1 "PCP" "Performance Co-Pilot"
.SH NAME
\f3pmgetopt\f1 \- Performance Co-Pilot shell script option parser
.SH SYNOPSIS
\f3$PCP_BINADM_DIR/pmgetopt\f1
[\f3\-c\f1|\f3\-\-config\f1 \f2file\f1]
[\f3\-p\f1|\f3\-\-progname\f1 \f2name\f1]
[\f3\-u\f1|\f3\-\-usage\f1]
[\f3\-\-\f1]
[\f2parameters\f1]
.SH DESCRIPTION
.de EX
.in +0.5i
.ie t .ft CB
.el .ft B
.ie t .sp .5v
.el .sp
.ta \\w' 'u*8
.nf
..
.de EE
.fi
.ie t .sp .5v
.el .sp
.ft R
.in
..
.B pmgetopt
is used to perform command line option parsing for shell scripts
used in the Performance Co-Pilot (PCP toolkit).
It is also used to generate usage messages for those scripts.
.PP
The parameters given to
.B pmgetopt
take two forms: initially, options specific to
.B pmgetopt
itself are passed in, and terminated using the \-\- mechanism.
Thereafter, all of the parameters passed into the shell script
should be passed (usually this is simply the "$@" variable).
.PP
The options specific to
.B pmgetopt
are as follows:
.TP 5
.BR \-c , \-\-config
A configuration
.I file
in the format described below is passed to
.B pmconfig 
using this option.
If this option is omitted, then
.B pmconfig 
will read its configuration from the standard input stream.
.TP
.BR \-p , \-\-progname
When parsing the calling shell scripts parameters, error and usage
messages will contain the given program
.I name
rather than referring to
.B pmgetopt
itself as the source of the error.
.TP
.BR \-u , \-\-usage
A usage message appropriate for the calling shell script to
present as its own can be generated using the
option.
.PP
.B pmgetopt
parses the given parameters, and produces output in a format
suitable for sourcing in the calling shell script.
When both short and long forms of an argument are allowed by
the specification,
.B pmgetopt
will always indicate the short form for simpler shell processing.
If arguments are presented that do not match the configuration,
a request for a usage message (\-\?) will be generated for the
calling script to respond to.
Any non-option parameters will be echoed back to the calling
script preceded by the double-hyphen delimiter.  Thus a script
should stop handling options when this delimiter is detected,
and begin the handling of any non-option arguments.
.PP
Unlike with the shell built-in
.I getopt
command, variables like $OPTARG are
not set and the calling script will typically employ use of the
shell built-in
.IR eval ,
.I set
and positional
.I shift
commands to ensure option processing occurs correctly.
.SH CONFIGURATION
The configuration format used by
.B pmgetopt
is intended to closely reflect the usage message which would be
generated in the presence of invalid arguments (or the 
.BR \-? , \-\-help
option).
.PP
There are primarily two types of configuration line \- commands
and options.
Commands allow metadata to be passed into the option processing
process, and options are the allowable command line options that
the shell script will accept.
Command lines are preceded by the hash character, whereas option
lines will always begin with a hyphen (either single or double).
Any other line in the configuration, which may include usage headers
or descriptive text, has no impact on the option parsing and will be
copied unmodified into the usage message.
.PP
The set of commands is:
.I getopt
(provide short-argument option specification manually,
if not present this will be generated from the options presented),
.I usage
(provide short one-line summary used at the head of the
usage message, which will be prefixed by the
.I progname
before reporting), and
.I end
which informs
.B pmgetopt
to stop processing further commands and options \- any subsequent
text encountered will be simply appended to the usage message.
.PP
A short-hand notation exists for each of the standard PCP options,
as described in
.BR PCPIntro (1).
If any of these options (e.g \f3\-\-host\f1) appears as a single word on
any line, it will be transformed into the appropriate option for the
shell script, including all metadata about that option (whether it
accepts an argument, both short and long option forms, and so on).
.PP
Use of the equals symbol ("=") indicates the presence of a required
argument to any option, for both short and long forms.
Any non-standard option must be accompanied by a non-empty description
of that argument.
.SH EXAMPLES
As an example, the following is a valid configuration:
.EX
# Usage: [options] node...

Options:
    --archive
    -d, --delay            pause between updates for archive replay
    --host
    --interval
    -i=INST, --insts=INST  comma-separated metrics instance list
    -r                     output raw counters (no rate conversion)
    --width=N              set the width of each column of output
    --timezone
    --help
.EE
.PP
This configuration will produce the following usage message,
when run as shown.
.EX
$ pmgetopt --usage --progname=clusterstat -- "$@"
Usage: clusterstat [options] node...

Options:
  -a FILE, --archive=FILE
                        metrics source is a PCP log archive
  -d, --delay           pause between updates for archive replay
  -h HOST, --host=HOST  metrics source is PMCD on host
  -t DELTA, --interval=DELTA
                        sampling interval
  -i INST, --insts=INST comma-separated metrics instance list
  -r                    output raw counters (no rate conversion)
  --width=N             set the width of each column of output
  -Z TZ, --timezone=TZ  set reporting timezone
  -?, --help            show this usage message and exit
.EE
.PP
Several examples of
.B pmgetopt
use form part of the PCP toolkit, in particular the
.BR pcp (1)
and
.BR pmlogmv (1)
scripts provide good reference examples.
.SH "PCP ENVIRONMENT"
Environment variables with the prefix
.B PCP_
are used to parameterize the file and directory names
used by PCP.
On each installation, the file
.I /etc/pcp.conf
contains the local values for these variables.
The
.B $PCP_CONF
variable may be used to specify an alternative
configuration file,
as described in
.BR pcp.conf (5).
.SH SEE ALSO
.BR pcp (1),
.BR pmlogmv (1),
.BR pmgetopt_r (3),
.BR pcp.conf (5)
and
.BR pcp.env (5).