Skip to content

Commit

Permalink
Merge pull request docopt#43 from offscale/master
Browse files Browse the repository at this point in the history
C89; Python packaging; MSVC support; PEP8; `EXIT_SUCCESS`/`EXIT_FAILURE`
  • Loading branch information
keleshev authored Aug 18, 2021
2 parents 15060c7 + 3682fc8 commit a8cdecf
Show file tree
Hide file tree
Showing 17 changed files with 1,577 additions and 949 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4

[*.py]
max_line_length = 119
43 changes: 43 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: PyPi publish

on:
push:
branches:
- 'master'
pull_request:
types:
- opened
- reopened

jobs:
test:
name: ${{ matrix.os.name }} ${{ matrix.python-version }}
runs-on: ${{ matrix.os.runs-on }}
strategy:
matrix:
python-version: [3.9]
os:
- name: Linux
runs-on: ubuntu-latest
python_platform: linux
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- name: install_dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade setuptools wheel
- name: PyPi release
run: |
pip install twine
python setup.py sdist bdist_wheel
python -m twine upload --repository pypi dist/*
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
TWINE_NON_INTERACTIVE: 1
if: matrix.python-version == '3.9' && matrix.os.name == 'Linux' && github.ref == 'refs/heads/master'
151 changes: 147 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,147 @@
*.o
*.out
*.py[co]
*.swp
build
dist
*.egg-info
# Jetbrains IDEs
.idea
out/
.project
.pydevproject
.vscode

# File-based project format
*.iws

# JIRA plugin
atlassian-ide-plugin.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
64 changes: 34 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
C-code generator for docopt language
====================================
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![PyPi publish](https://github.com/offscale/docopt.c/actions/workflows/main.yml/badge.svg)](https://github.com/offscale/docopt.c/actions/workflows/main.yml)
[![PyPi: release](https://img.shields.io/pypi/v/docopt_c.svg?maxAge=3600)](https://pypi.org/project/docopt_c)

Note, *at this point the code generator handles only options*
(positional arguments, commands and pattern matching will follow).
Expand All @@ -10,12 +13,12 @@ Note, *at this point the code generator handles only options*
Naval Fate.
Usage:
naval_fate.py ship create <name>...
naval_fate.py ship <name> move <x> <y> [--speed=<kn>]
naval_fate.py ship shoot <x> <y>
naval_fate.py mine (set|remove) <x> <y> [--moored|--drifting]
naval_fate.py --help
naval_fate.py --version
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.
Expand All @@ -28,43 +31,44 @@ Options:
### Step 2. Generate the C code

```bash
$ python docopt_c.py -o docopt.c example.docopt
$ python -m docopt_c -o docopt.c example.docopt
```

or by using pipe

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

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

```c
#include "docopt.c"
#include "docopt.h"

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 0;
struct DocoptArgs args = docopt(argc, argv, /* help */ 1, /* version */ "2.0rc2");

puts("Commands");
printf("\tmine == %s\n", args.mine ? "true" : "false");
printf("\tmove == %s\n", args.move ? "true" : "false");
printf("\tcreate == %s\n", args.create ? "true" : "false");
printf("\tremove == %s\n", args.remove ? "true" : "false");
printf("\tset == %s\n", args.set ? "true" : "false");
printf("\tship == %s\n", args.ship ? "true" : "false");
printf("\tshoot == %s\n", args.shoot ? "true" : "false");
puts("Arguments");
printf("\tx == %s\n", args.x);
printf("\ty == %s\n", args.y);
puts("Flags");
printf("\t--drifting == %s\n", args.drifting ? "true" : "false");
printf("\t--help == %s\n", args.help ? "true" : "false");
printf("\t--moored == %s\n", args.moored ? "true" : "false");
printf("\t--version == %s\n", args.version ? "true" : "false");
puts("Options");
printf("\t--speed == %s\n", args.speed);

return EXIT_SUCCESS;
}
```
Expand Down
Loading

0 comments on commit a8cdecf

Please sign in to comment.