Skip to main content

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.


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

  dq info <queue_file>
  dq --help

  -h --help  Prints a short usage summary.

Convert the USAGE file into a Ragel file: 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)

    void *qu = NULL;

    if (
    else if (
        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.

Files for docopt2ragel, version 0.1.4
Filename, size File type Python version Upload date Hashes
Filename, size docopt2ragel-0.1.4-py2.py3-none-any.whl (6.9 kB) File type Wheel Python version 2.7 Upload date Hashes View
Filename, size docopt2ragel-0.1.4.tar.gz (4.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page