* * * * *

                      Ideas in parsing the command line

> For any non-trivial script, even for personal consumption, it's necessary
> to supply usage text. The novelty of Lapp is that it starts from that point
> and defines a loose format for usage strings which can specify the names
> and types of the parameters.
>
> An example will make this clearer:
>
> -----[ Lua ]-----
>       -- scale.lua
>         require 'lapp'
>         local args = lapp [[
>         Does some calculations
>           -o,--offset (default 0.0)  Offset to add to scaled number
>           -s,--scale  (number)  Scaling factor
>            <number> (number )  Number to be scaled
>         ]]
>
>         print(args.offset + args.scale * args.number)
> -----[ END OF LINE ]-----
>

“lua-users wiki: Lapp Framework [1]”

The thought of parsing the usage text for parsing the command line never
occured to me, and I think it's brilliant.

Now, when I want to modify the command line of a program I wrote (and this is
mostly in C, by the way), there are four locations I have to edit:

 1. An enumeration specifying the “short” form of the command line option
 2. A structure describing both the short and the long forms of a command
    line option
 3. A switch statement that processes the command line options from
    getopt_long()
 4. The text printed out describing the command line options

This method though, there's only one area I would have to edit.

Now granted, this is only for Lua, but I can't see why something similar for
other languages can't be done.

[1] http://lua-users.org/wiki/LappFramework

Email author at [email protected]