pyCLIG is a Python reimplementation of Harald Kirsch's clig (Command Line Interface Generator), which was originally written in TCL and last released in 2004.
Given a .cli specification file, pyCLIG generates two C source files:
<base>.h— struct typedef and extern declarations<base>.c—parseCmdline(),usage(), and supporting helpers
The generated C code is intended to be functionally equivalent to what the
original clig produced.
pyclig [-o outprefix] [-t C[,man]] [-d] [--style {default,kr}] <specfile.cli>
| Flag | Description |
|---|---|
-o prefix |
Output file prefix (default: specfile without extension) |
-t TYPE |
Output type(s): C and/or man, comma-separated (default: C) |
-d |
Also generate showOptionValues() debug function |
--style kr |
Emit K&R-formatted output, equivalent to indent -kr -nut -l85 (4-space indent, function signature on one line, space before ( in control flow) |
The spec file uses a TCL-compatible syntax. Each directive is one logical
line (backslash-newline continues to the next line). Brace quoting {...},
double quoting "...", and [exec cmd] substitution are supported.
Name <program-name>
Usage {one-line description}
Version [exec date +%Y-%m-%d]
Commandline <varname>
Description {Text for the DESCRIPTION section of the man page.}
Author {Name and contact for the AUTHOR section of the man page.}
SeeAlso {related(1), programs(1)}
Flag -flag varname {description}
String -opt varname {description} [-c cmin cmax] [-d default ...] [-m]
Int -opt varname {description} [-c cmin cmax] [-r rmin rmax] [-d default ...] [-m]
Long -opt varname {description} [-c cmin cmax] [-r rmin rmax] [-d default ...] [-m]
Float -opt varname {description} [-c cmin cmax] [-r rmin rmax] [-d default ...] [-m]
Double -opt varname {description} [-c cmin cmax] [-r rmin rmax] [-d default ...] [-m]
Rest varname {description} [-c cmin cmax]
Description, Author, and SeeAlso text is inserted verbatim into the
corresponding man page sections. Multi-line content can span multiple lines
inside brace quoting:
Description {
This program does something useful.
A second paragraph with more detail.
}
Use oo and -oo for positive and negative infinity in -c and -r
arguments. Negative numeric defaults must be quoted to prevent them from
being misread as option flags: use " -1" (with a leading space inside the
quotes) or {-1}.
The generated C code is substantially the same as the original, but with the following improvements to eliminate compiler warnings on modern toolchains:
isspaceUB —isspace((int)*end)invokes undefined behaviour whencharis signed and the value is > 127. Changed toisspace((unsigned char)*end)throughout.
-
char varP→int varP— Flag presence fields in the generated struct werechar; changed tointto avoid implicit narrowing and to match the= 1assignments more naturally. -
const char *parameters — Helper functions that only read a string argument now takeconst char *instead ofchar *, silencing-Wwrite-stringswarnings at call sites. -
checkFloatConversionconditional — Thisstatichelper is only emitted when the spec actually usesFloatorDoubleoptions, avoiding-Wunused-functionwarnings on specs that have only integer/string options. -
NULLinstead of(type*)0— Pointer fields in the static struct initialiser useNULLrather than explicit zero-casts. -
int missingMandatory— Changed fromchartoint.
-
fputsinstead offprintf(stderr, "%s", ...)inusage()— removes a redundant format-string call for string constants, and eliminates-Wformat-nonliteralwarnings with strict compilers. -
Typo fixed — "to large" / "to small" in overflow error messages corrected to "too large" / "too small".
-
No LCLint annotations —
/*@null*/,/*@shared*/, and similar lclint directives have been removed; they served a static-analysis tool that is no longer in common use and were syntactically surprising.
Original clig:
- Author: Harald Kirsch clig@geggus.net
- License: GNU General Public License, version 2
- Last release: 2004
pyCLIG:
- Author: Scott Ransom (port/modernisation)
- License: GNU General Public License, version 2 (see
LICENSE)