Skip to main content

C generator for language for description of command-line interfaces

Project description

C-code generator for docopt language

License PyPi publish PyPi: release

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

Naval Fate.

Usage:
  naval_fate ship create <name>...
  naval_fate ship <name> move <x> <y> [--speed=<kn>]
  naval_fate ship shoot <x> <y>
  naval_fate mine (set|remove) <x> <y> [--moored|--drifting]
  naval_fate --help
  naval_fate --version

Options:
  -h --help     Show this screen.
  --version     Show version.
  --speed=<kn>  Speed in knots [default: 10].
  --moored      Moored (anchored) mine.
  --drifting    Drifting mine.

Step 2. Generate the C code

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

or by using pipe

$ cat example.docopt | python -m docopt_c > docopt.c

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

#include <stdlib.h>
#include "docopt.c"

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

    printf("Commands\n");
    printf("    mine == %s\n", args.mine ? "true" : "false");
    printf("    move == %s\n", args.move ? "true" : "false");
    printf("    create == %s\n", args.create ? "true" : "false");
    printf("    remove == %s\n", args.remove ? "true" : "false");
    printf("    set == %s\n", args.set ? "true" : "false");
    printf("    ship == %s\n", args.ship ? "true" : "false");
    printf("    shoot == %s\n", args.shoot ? "true" : "false");
    printf("Arguments\n");
    printf("    x == %s\n", args.x);
    printf("    y == %s\n", args.y);
    printf("Flags\n");
    printf("    --drifting == %s\n", args.drifting ? "true" : "false");
    printf("    --help == %s\n", args.help ? "true" : "false");
    printf("    --moored == %s\n", args.moored ? "true" : "false");
    printf("    --version == %s\n", args.version ? "true" : "false");
    printf("Options\n");
    printf("    --speed == %s\n", args.speed);

    return EXIT_SUCCESS;
}

Step 4. Profit!

$ c99 example.c -o example.out
$ ./example.out mine --drifting --speed=20
Commands
    mine == true
    move == false
    create == false
    remove == false
    set == false
    ship == false
    shoot == false
Arguments
    x == (null)
    y == (null)
Flags
    --drifting == true
    --help == false
    --moored == false
    --version == false
Options
    --speed == 20

Development

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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

docopt_c-0.0.3.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

docopt_c-0.0.3-py3-none-any.whl (24.3 kB view details)

Uploaded Python 3

File details

Details for the file docopt_c-0.0.3.tar.gz.

File metadata

  • Download URL: docopt_c-0.0.3.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6

File hashes

Hashes for docopt_c-0.0.3.tar.gz
Algorithm Hash digest
SHA256 9e953bcc50920f313b73fd8b9a8ff70aeabd4c0d1a8d0b70764752f0ce0d05d4
MD5 cecfb4e900936853db2197035d164491
BLAKE2b-256 922f68a72a1c68d9c51cfc89db213ab011a3cbb2b65ec471ef9fd6a1ca478599

See more details on using hashes here.

File details

Details for the file docopt_c-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: docopt_c-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 24.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6

File hashes

Hashes for docopt_c-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 28561104e39a297d96f17ad27327630bb8902ba7c0747e14d40823f4e704d895
MD5 42a59be34ac749fbc179be0fb7fa40c1
BLAKE2b-256 a6b225081183291cbf777e6c7ae4a10d9f2872bd345bb078ccea7a703831ad98

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page