Convert your docopt usage text into a Ragel FSM
Project description
docopt2ragel makes command line interface parsing easy!
docopt2ragel parses docopt USAGE text and outputs a Ragel finite state machine for parsing the CLI.
You can then use Ragel to output the finite state machine into C source code.
Example
Create a USAGE file using docopt’s declarative format. See below for example contents:
dq - a command line tool for duraqueue the dead simple queue
Usage:
dq info <queue_file>
dq --help
Options:
-h --help Prints a short usage summary.
Convert the USAGE file into a Ragel file:
docopt2ragel.py USAGE > usage.rl
Convert the Ragel file into a C file:
ragel usage.rl
Import the generated file into your source:
#include "usage.c"
int main(int argc, char **argv)
{
int e;
options_t opts;
e = parse_options(argc, argv, &opts);
if (-1 == e)
{
exit(-1);
}
void *qu = NULL;
if (opts.help)
{
show_usage();
exit(0);
}
else if (opts.info)
{
qu = dqueuer_open(opts.queue_file);
}
if (qu)
printf("Item count: %d\n", dqueue_count(qu));
return 1;
}
For real life examples see:
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
docopt2ragel-0.1.4.tar.gz
(4.9 kB
view details)
Built Distribution
File details
Details for the file docopt2ragel-0.1.4.tar.gz
.
File metadata
- Download URL: docopt2ragel-0.1.4.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93583cc5e7d5b2e9170d4833bba0a1196531cf5995ea3d672ce5a15a4076e14f |
|
MD5 | 400e4a755cc22f4bc2ca71ed131d6f7f |
|
BLAKE2b-256 | 129f23bf9fa5eb0cf2c0299b6cb2731b61e4d77da40565d1e8799330942c740b |
File details
Details for the file docopt2ragel-0.1.4-py2.py3-none-any.whl
.
File metadata
- Download URL: docopt2ragel-0.1.4-py2.py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0444717ef228fcd7e56768e2a13c0aedc7f5e8a610c71894b559ded7f57297c3 |
|
MD5 | 03da17c21e8d0d95e6ca425f52b087df |
|
BLAKE2b-256 | d958a903f6787f1c54c769c0b3973580d88bf48a497f2cc3a0700294e8b18e3c |