1 .TH lopsub-suite 5 "DATE()" GIT_VERSION()
3 lopsub-suite \- lopsub suite syntax
7 describes the options to a command line utility with zero or more
8 related subcommands. The
10 utility translates a lopsub suite into either C source code or a manual
11 page. The generated C code can be compiled and linked against the
12 lopsub library to produce command line parsers for the main command
13 and all subcommands defined in the suite.
15 This document explains the format of a lopsub suite. The overall
16 structure is as follows:
22 [supercommand sup_cmd]
23 command directives for sup_cmd
28 command directives for sub1
29 [option opt_1_to_sub1]
30 option directives for opt_1
33 ... (further subcommands)
36 ... (optional extra section for man page)
38 ... (further extra sections)
43 line which declares the name of the suite. The
45 all subsequent lines up to the first
49 line, state further properties of the suite which are unrelated to
50 any particular command, for example the version number. All available
51 suite directives are summarized below.
57 lines indicate the beginning of a command of the suite. The part between this
61 .B command directives,
62 for example the purpose and the description of the named command.
63 See the section on command directives below.
65 Supercommands and subcommands share the same set of possible command
66 directives. They differ mainly in the way the documentation is
67 formated. There can only be one supercommand but arbitrary many
68 subcommands. For example, the supercommand could be the name of
69 the application, and the subcommands could be "load", "save" "info"
70 and "quit". The subcommand would be passed as the first non-option
71 argument to the supercommand, followed by options specific to that
74 Of course it is possible to define no subcommands at all. Conversely,
75 one can define only subcommands but no supercommand. This makes
76 sense if the commands are run by some other means, for example in an
77 interactive session from a command prompt.
79 Within the command section, an
81 line starts an option to the current command. It is followed by
83 which specify, for example, whether or not the option takes
84 an argument. All supported option directives are listed in the
85 corresponding section below.
87 Further material for man output can be included between the
92 This text will not be included in the generated .c and .h files and
93 is thus also not part of the short and long help available at run
94 time. The text is not interpreted except that leading whitespace is
95 stripped from each line. Arbitrary roff source can be included here.
97 Empty lines and lines starting with a hash character (#) are
100 Most directives of this section are only relevant for man page output (with
102 being the exception), they are ignored for C output.
105 The optional text for an unnumbered section heading at the beginning of the
109 Sets the title of the man page. Defaults to the name of the
110 supercommand. If this is not given and the suite has no supercommand,
111 the .TH macro to set the title of the man page is omitted.
114 Sets the man page section. Defaults to 1 (user commands). Both title
115 and section are positioned at the left and right in the header line.
118 This text is positioned in the middle of the footer line of the man page. It is
119 common to set this to the date of the last nontrivial change that was made to
120 the man page. Defaults to the current date.
123 Positioned at the left in the footer line. Defaults to the empty string. The
124 value of this directive is ignored if a version string is explicitly requested
131 Centered in the header line. Defaults to "User commands".
136 The text enclosed between
140 is shown between the supercommand (if any) and the subcommand list.
141 Concluding remarks after the subcommand list may be added in the same
146 Both texts will become part of the manual page, but are not not part
147 of the short or long help. Like for the
149 directive, arbitrary roff source may be included here.
152 This text is shown at the bottom of each command before the value of the
153 aux_info directive. If no
155 is specified for a command, the prefix is omitted as well. If
157 is not given, the empty string is assumed.
160 This text is only used for header output. The argument for the generated macro
161 call is set to this value for all commands for which no
163 directive is given. If no
165 directive is given, the value 0 is used as the argument for the macro.
166 .SH COMMAND DIRECTIVES
169 A single line containing the purpose of the command. This text is printed in
170 the short and long help, and is also included in the man page.
175 Arbitrary plain text enclosed between
179 The text may be split over multiple lines and paragraphs. The
180 description of the supercommand (if any) becomes the description of
181 the manual page, which is shown after the command summary and before
182 the list of options. The descriptions of all commands are included
183 in the manual page and in the long help text but not in the short help.
185 Closing remarks for the command can be added in a similar way by enclosing
190 This text will be positioned after the option list.
193 Custom synopsis of the command. If this is not given, the synopsis text will be
194 auto-generated from the options and the value of the
199 Name of the command line arguments which are not related to any option,
200 for example file names. This text will be included in the automatically
201 generated synopsis text.
203 If this is not given, the command is assumed to take no arguments other than
204 the specified options and their arguments. For such commands the attempt to
205 parse an argv[] vector fails if it contains further non-option arguments.
208 This directive is special because its value is not included in the generated .c
209 file but in the header file. More precisely, the preprocessor macro
210 .B \%LSG_SUITENAME_AUX_INFOS
211 will be defined which expands to a series of macro calls to
212 .B \%LSG_SUITENAME_AUX_INFO(val_n),
213 one for each command of the suite, where
215 is the (unquoted) value of the
217 directive of the nth command. Commands for which no
219 directive was specified receive a value of zero. The
220 .B \%LSG_SUITENAME_AUX_INFO
221 macro is supposed to be defined by the application.
222 Hence it is up to the application to make the expansion of
223 .B \%LSG_SUITENAME_AUX_INFOS
226 The value, if specified, is also copied to the man page at the end of the
227 section for the command.
229 .SH OPTION DIRECTIVES
232 The optional single-letter equivalent for the option. If this is
233 specified, the option may be given either in the GNU-style long
234 option format with two leading dashes or in the short form with a
235 single dash. Otherwise only the long form will be accepted. As usual,
236 multiple short option flags may be combined.
239 A single line which summarizes the option. This text is included in
240 both the short and the long help and in the man page. Defaults to
244 A description for the type of the values for the option. The given text
245 is printed in the synopsis of the command, which is part of the short
246 and the long help and the man page. It defaults to the string "val".
248 This directive is ignored for flag options (options without an argument).
251 This directive determines whether the option takes an argument. The
253 .B no_arg, required_arg
256 which indicate, respectively, that the option takes no argument at all,
257 an argument which is mandatory, or an argument which may be omitted. The
260 Hence an option works as a flag if the
262 directive is not given.
264 Note that arguments to options which take an optional argument must
265 be given as --foo=bar rather than --foo bar because the latter form
269 For flag options this directive should be set to
271 or not set at all. For options which take an argument, the value of the directive
272 determines the type of the argument.
275 for options which take a string argument, and
280 for options which take a numeric argument.
283 Lopsub maintains for each option a bitmask which contains the value
284 of each possible flag for this option. Flags may be accumulated by
285 defining multiple flag directives in the suite. Note there is no
286 equal sign between the
288 directive and its value.
290 The following flags are defined.
294 This flag instructs the lopsub library to keep track of all given
295 arguments to an option, not just one as for ordinary options. This
296 is only relevant for options which take an (optional or required)
300 Instruct the parser to fail if this option is not given in the
301 argument vector. If an option may be given at the command line or
302 in the config file, this flag should be avoided because the command
303 line argv vector will not be parsed successfully if the option is
304 only given in the config file. The recommended way to deal with
305 this situation is to parse command line and config file separately,
306 then merge the two parse results and check in the application if the
307 option is given in the merged parse result.
310 This flag indicates that the current option is in fact not a real option.
315 are both ignored. The purpose of this flag is to add additional
316 information for the help output and the man page.
320 Create an enumerable option.
322 Enumerable options take one out of a fixed set of possible values
323 which are predefined in the suite. Such options are always of type
324 string. It is an error if a different argument type was specified or
325 if the option was defined to not take an argument.
327 The syntax for the array of values is
330 values = {ID_0 = "string_0", ..., ID_N = "string_N"}
333 For each option for which the
335 directive was specified, the lopsubgen command generates a C
336 enumeration which contains the given identifiers. This allows
337 referring to each possible value through a numeric constant.
340 This directive makes only sense for options which take an argument. For
341 such options it defines the value the option parser provides
342 automatically if the option is not given in the argument vector.
346 is specified in the suite, and the option is not given in the argument
347 vector either, the implied value depends on the argument type. For
348 numeric options, a value of zero is assumed. For options which take
349 a string argument, a NULL pointer is returned. For enum options,
350 the first possible value (index zero) is taken as the default.
353 The detailed, multi-line help text for the current option. Included
354 in the man page and the long help.
356 A minimal suite and the corresponding "application".
364 purpose = hello world
366 summary = add "world"
373 #include <stdio.h> /* printf(3) */
374 #include <stdlib.h> /* exit(3) */
376 #include "hello.lsg.h"
378 int main(int argc, char **argv)
380 struct lls_parse_result *lpr;
381 const struct lls_opt_result *result;
382 const struct lls_command *cmd = lls_cmd(0, hello_suite);
385 ret = lls_parse(argc, argv, cmd, &lpr, NULL);
387 fprintf(stderr, "%s\\n", lls_strerror(-ret));
391 result = lls_opt_result(LSG_HELLO_HELLO_OPT_WORLD, lpr);
392 if (lls_opt_given(result))
405 $ lopsubgen --gen-c --gen-h < hello.suite
417 $ cc hello.c hello.lsg.c -o hello -llopsub
428 option not recognized
430 invalid number of arguments
433 Generate and examine the manual page:
436 $ lopsubgen --gen-man < hello.suite
437 $ man -l ./hello.lsg.man