GithubHelp home page GithubHelp logo

jochman / mkdocs-click Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mkdocs/mkdocs-click

0.0 1.0 0.0 148 KB

An MkDocs extension to generate documentation for Click command line applications

Home Page: https://pypi.org/project/mkdocs-click

License: Apache License 2.0

Python 96.48% Shell 3.52%

mkdocs-click's Introduction

mkdocs-click

Tests Python versions Package version

An MkDocs extension to generate documentation for Click command line applications.

Installation

Install from PyPI:

pip install mkdocs-click

Quickstart

Add mkdocs-click to Markdown extensions in your mkdocs.yml configuration:

site_name: Example
theme: readthedocs

markdown_extensions:
    - mkdocs-click

Add a CLI application, e.g.:

# app/cli.py
import click

@click.group()
def cli():
    """Main entrypoint."""

@cli.command()
@click.option("-d", "--debug", help="Include debug output.")
def build(debug):
    """Build production assets."""

Add a mkdocs-click block in your Markdown:

# CLI Reference

This page provides documentation for our command line tools.

::: mkdocs-click
    :module: app.cli
    :command: cli

Start the docs server:

mkdocs serve

Tada! ๐Ÿ’ซ

Usage

Documenting commands

To add documentation for a command, add a mkdocs-click block where the documentation should be inserted.

Example:

::: mkdocs-click
    :module: app.cli
    :command: main

For all available options, see the Block syntax.

Multi-command support

When pointed at a group (or any other multi-command), mkdocs-click will also generate documentation for sub-commands.

This allows you to generate documentation for an entire CLI application by pointing mkdocs-click at the root command.

Tweaking header levels

By default, mkdocs-click generates Markdown headers starting at <h1> for the root command section. This is generally what you want when the documentation should fill the entire page.

If you are inserting documentation within other Markdown content, you can set the :depth: option to tweak the initial header level. Note that this applies even if you are just adding a heading.

By default it is set to 0, i.e. headers start at <h1>. If set to 1, headers will start at <h2>, and so on. Note that if you insert your own first level heading and leave depth at its default value of 0, the page will have multiple <h1> tags, which is not compatible with themes that generate page-internal menus such as the ReadTheDocs and mkdocs-material themes.

Full command path headers

By default, mkdocs-click outputs headers that contain the command name. For nested commands such as $ cli build all, this also means the heading would be ## all. This might be surprising, and may be harder to navigate at a glance for highly nested CLI apps.

If you'd like to show the full command path instead, turn on the Attribute Lists extension:

# mkdocs.yaml

markdown_extensions:
    - attr_list
    - mkdocs-click

mkdocs-click will then output the full command path in headers (e.g. ## cli build all) and permalinks (e.g. #cli-build-all).

Note that the table of content (TOC) will still use the command name: the TOC is naturally hierarchal, so full command paths would be redundant. (This exception is why the attr_list extension is required.)

Reference

Block syntax

The syntax for mkdocs-click blocks is the following:

::: mkdocs-click
    :module: <MODULE>
    :command: <COMMAND>
    :prog_name: <PROG_NAME>
    :depth: <DEPTH>
    :style: <STYLE>

Options:

  • module: Path to the module where the command object is located.
  • command: Name of the command object.
  • prog_name: (Optional, default: same as command) The name to display for the command.
  • depth: (Optional, default: 0) Offset to add when generating headers.
  • style: (Optional, default: plain) Style for the options section. The possible choices are plain and table.

mkdocs-click's People

Contributors

florianveaux avatar florimondmanca avatar frankier avatar max-frank avatar ofek avatar yudai-nkt avatar yuyu2172 avatar

Watchers

 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.