-
Notifications
You must be signed in to change notification settings - Fork 1
/
README
56 lines (44 loc) · 2.04 KB
/
README
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
BASH OPTPARSE
an advanced command line
parsing system for Bash
========================
Copyright (C) 2011-2012 Carlo Baldassi <carlobaldassi@gmail.com>
This program is intended as an advanced replacement of getopt
for bash. Its goals are to improve the simplicity, clarity and
ease of maintenance in the definition of command line parsing rules,
while at the same time adding many additional features, automations
and more.
It is somehow similar in spirit to python's optparse, or
boost::program_options or others, i.e. it provides a framework
in which the program options and arguments are described in a
compact format, leaving to bash_optparse all the work of performing
parsing, setting default values, implementing dynamic type checks
and range checks over the value of the variables, auto-generating
a nicely formatted help screen etc.
Furthermore, it can be integrated in bash readline completion.
The typical usage in a script could be something like this:
. bash_optparse << EOF
OPTIONS_BEGIN
perc FLOAT x [0:100] 50 "Select percentage"
OPTIONS_END
ARGUMENTS_BEGIN
infile False "input file"
ARGUMENTS_END
EOF
The line in the OPTIONS block in the example describes a long
option named --perc, associated to a varaible of the same name
($perc), of type FLOAT, whose range is between 0 and 100, and
which defaults to 50. A short option -p is also automatically
added as an alias to the long option. Calling the script with
the (automatically added) --help option, one would get a
corresponding auto-generated help line:
-p, --perc <x> Select percentage (<x>=float in [0.0:100.0],
default=50)
The line in the ARGUMENTS block line describes how to pass an
optional argument, which will be stored in the variable $infile.
See `example_script_simple', `example_functions' and
`example_script' in the `doc' directory for more information.
The explanation of the syntax can be found in the comments to the
`example_script' code.
Also, see the `README' file in the `completion' directory for
information about the integrtion with bash completion.