GithubHelp home page GithubHelp logo

docopt.c's Introduction

C-code generator for docopt language

Note, at this point the code generator handles only options (positional arguments, commands and pattern matching will follow).

Step 1. Describe your CLI in docopt language

Usage:
  program --tcp [--host=<host>] [--port=<port>] [--timeout=<seconds>]
  program --serial [--port=<port>] [--baud=<baud>] [--timeout=<seconds>]
  program -h | --help | --version

Options:
  -h, --help               Show this screen.
  --version                Print version and exit.
  --tcp                    TCP mode.
  --serial                 Serial mode.
  --host=<host>            Target host [default: localhost].
  -p, --port=<port>        Target port [default: 1234].
  -t, --timeout=<seconds>  Timeout time in seconds [default: 10]
  -b, --baud=<baud>        Target port [default: 9600].

Step 2. Generate the C code

$ python docopt_c.py -o docopt.c example.docopt

or by using pipe

$ cat example.docopt | python docopt_c.py > docopt.c

Step 3. Include the generated docopt.c into your program

#include "docopt.c"

int main(int argc, char *argv[])
{
    DocoptArgs args = docopt(argc, argv, /* help */ 1, /* version */ "2.0rc2");

    printf("--help == %s\n", args.help ? "true" : "false");
    printf("--version == %s\n", args.version ? "true" : "false");
    printf("--tcp == %s\n", args.tcp ? "true" : "false");
    printf("--serial == %s\n", args.serial ? "true" : "false");
    printf("--host == %s\n", args.host);
    printf("--port == %s\n", args.port);
    printf("--timeout == %s\n", args.timeout);
    printf("--baud == %s\n", args.baud);
}

Step 4. Profit!

$ c99 example.c -o example.out
$ ./example.out --tcp --host=127.0.0.1 --baud=4800
--help == false
--version == false
--tcp == true
--serial == false
--host == 127.0.0.1
--port == 1234
--timeout == 10
--baud == 4800

Development

See the Python version's page for more info on developing.

docopt.c's People

Contributors

ffunenga avatar kblomqvist avatar tjk avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.