Giter VIP home page Giter VIP logo

md-click's Introduction

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.

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:

> pip install md-click

Usage

Create md files per each command, in format of parent-command, under the --docsPath directory.

for example, we have the next click python module:

# app/cli.py
import click

@click.group('namer')
@click.option('--debug', help='Should I run on Debug?', is_flag=True)
def main(**kwargs):
  """ A namer CLI """
  debug = kwargs.get('debug')
  if debug:
    click.secho('is Debug? True', color='green')

@main.command('full')
@click.option('--name', help='The user name', required=True, type=str)
@click.option('--lastName', help='The last Name', required=False, type=str)
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:

> mdclick dumps --baseModule=app.cli --baseCommand=main --docPath=./docs/commands

The output:

./docs/commands/namer.md
./docs/commands/namer-full.md

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.

md-click's People

Contributors

alonreznik avatar shalgrim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

md-click's Issues

Can't find local modules

The tool doesn't find modules in the current working directory when it's installed from pip, which is what I would expect it to be used for.
Example of local file:

$ cat lucli.py 
import click

@click.group()
def cli():
    """Your standard, everyday lunch CLI."""
    pass


@cli.command()
@click.option('-dish', metavar='thing', envvar='DISH', default='burger',
                show_default=True, help='The meat dish to order')
def order_meat(dish: str):
    """Orders a meat dish."""
    click.echo(f'Meat is neat! One {dish} please!')


@cli.command()
@click.option('-dish', metavar='<thang>', envvar='DISH', default='penne',
              show_default=True, help='The type of pastas to order')
@click.option('-quantity', metavar='<quantity>', default=5,
              show_default=True, help='The amount of pasta dishes to order')
def order_pastas(dish: str, quantity: int):
    """Orders a bunch of pasta dishes."""
    click.echo(f'Pasta is a musta! {quantity} serving(s) of {dish} please!')

And when running the tool:

$ mdclick dumps --baseModule=lucli --baseCommand=cli --docsPath=docs/_build/md-click/
Creating a new documents from lucli.cli into docs/_build/md-click/
Could not find module: lucli. Error: No module named 'lucli'

If I add the current working directory to the Python path at the beginning of main.py:

import sys
import os
sys.path.insert(0, os.getcwd())

then it works:

$ mdclick dumps --baseModule=lucli --baseCommand=cli --docsPath=docs/_build/md-click/
Creating a new documents from lucli.cli into docs/_build/md-click/
Created docs under docs/_build/md-click/

but I'm not sure that's a good solution.

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.