diff --git a/.github/workflows/pypi-test.yml b/.github/workflows/pypi-test.yml index 9c1bfc6..53f29ff 100644 --- a/.github/workflows/pypi-test.yml +++ b/.github/workflows/pypi-test.yml @@ -9,16 +9,16 @@ on: jobs: build-n-publish: name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@main name: Checkout Main - - name: Set up Python 3.8 + - name: Set up Python 3.11 uses: actions/setup-python@v1 with: - python-version: 3.8 + python-version: 3.11 - name: Run Tests - - run: python -m unittests tests/test_main.py + run: python -m unittest tests/test_main.py diff --git a/README.md b/README.md index b1ce0b1..03c4b38 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,21 @@ # MD Click + MD-Click is a command line tool for creating `.md` files for any python's click CLI projects. # The Problem + After creating new CLI project using click, we couldn't found out any tool that generates automatic -`.md` files documentation per each command. This is the reason we've create this quick and easy tool. +`.md` files documentation per each command. This is the reason we've created this quick and easy tool. # The Solution + MD-Click creates `.md` files per each command exists under the `click` project CLI. The tool runs recursively and generates a markdown file per each command, and sub commands. # Installation Just install it using pip: + ```bash > pip install md-click ``` @@ -41,14 +45,14 @@ def full_name(**kwargs): """ A CLI that gets name and last name and returns the full name""" firstname = kwargs.get('name') lastname = kwargs.get('lastname') - + click.secho(f'The full name is: {firstname} {lastname}', color='yellow') ``` and we want to create a nice md files per each command, we'll run the next cli command: ```shell -> mdclick dumps --baseModule=app.cli --baseCommand=main --docPath=./docs/commands +> mdclick dumps --baseModule=app.cli --baseCommand=main --docsPath=./docs/commands ``` The output: @@ -60,4 +64,3 @@ The output: As you can assume, all of the markdown files under `docs/commands` in this repository, generated automatically by `mdclick` command. Use them as a reference. - diff --git a/md_click/main.py b/md_click/main.py index cdaef4f..3811a42 100644 --- a/md_click/main.py +++ b/md_click/main.py @@ -1,6 +1,7 @@ -import click -import pathlib import importlib +import pathlib + +import click md_base_template = """ # {command_name} @@ -50,11 +51,11 @@ def dump_helper(base_command, docs_dir): options = { opt.name: { "usage": '\n'.join(opt.opts), - "prompt": opt.prompt, - "required": opt.required, - "default": opt.default, - "help": opt.help, - "type": str(opt.type) + "prompt": getattr(opt, "prompt", None), + "required": getattr(opt, "required", None), + "default": getattr(opt, "default", None), + "help": getattr(opt, "help", None), + "type": str(getattr(opt, "type", None)) } for opt in helpdct.get('params', []) } @@ -87,10 +88,12 @@ def dump_helper(base_command, docs_dir): with open(md_file_path, 'w') as md_file: md_file.write(md_template) + @click.group() def cli(): pass + @cli.command('dumps') @click.option('--baseModule', help='The base command module path to import', required=True) @click.option('--baseCommand', help='The base command function to import', required=True) diff --git a/requirements.txt b/requirements.txt index 01fa418..cdda0dc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -click>=7.0.0,<=7.1.2 \ No newline at end of file +click>=7.0.0,<8.2.0 diff --git a/setup.py b/setup.py index 3203b37..12e6251 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,4 @@ from setuptools import setup, find_packages -from md_click import __version__ with open('requirements.txt', 'r') as req: install_requires = req.readlines()