GithubHelp home page GithubHelp logo

ewels / rich-click Goto Github PK

View Code? Open in Web Editor NEW
570.0 4.0 33.0 8.71 MB

Format click help output nicely with rich.

Home Page: https://ewels.github.io/rich-click/

License: MIT License

Python 100.00%
cli click colored coloured help python rich styled styles

rich-click's Introduction

rich-click logo

Richly rendered command line interfaces in click.

PyPI Test Coverage badge Lint code badge


Documentation  ·  Source Code  ·  Changelog


rich-click is a shim around Click that renders help output nicely using Rich.

  • Click is a "Python package for creating beautiful command line interfaces".
  • Rich is a "Python library for rich text and beautiful formatting in the terminal".

The intention of rich-click is to provide attractive help output from Click, formatted with Rich, with minimal customisation required.

Features

  • 🌈 Rich command-line formatting of click help and error messages
  • 😌 Same API as Click: usage is simply import rich_click as click
  • 💫 Nice styles by default
  • 💻 CLI tool to run on other people's tools (prefix the command with rich-click)
  • 📦 Export help text as HTML or SVG
  • 🎁 Group commands and options into named panels
  • ❌ Well formatted error messages
  • 🔢 Easily give custom sort order for options and commands
  • 🎨 Extensive customisation of styling and behaviour possible

Installation

pip install rich-click

Read the docs for all supported installation methods.

Examples

Simple Example

To use rich-click in your code, replace import click with import rich_click as click in your existing click CLI:

import rich_click as click

@click.command()
@click.option("--count", default=1, help="Number of greetings.")
@click.option("--name", prompt="Your name", help="The person to greet.")
def hello(count, name):
    """Simple program that greets NAME for a total of COUNT times."""
    for _ in range(count):
        click.echo(f"Hello, {name}!")

if __name__ == '__main__':
    hello()

python examples/11_hello.py --help

Screenshot from examples/11_hello.py

More complex example

python examples/03_groups_sorting.py

Screenshot from examples/03_groups_sorting.py

Usage

This is a quick overview of how to use rich-click. Read the docs for more information.

There are a couple of ways to begin using rich-click:

Import rich_click as click

Switch out your normal click import with rich_click, using the same namespace:

import rich_click as click

That's it! ✨ Then continue to use Click as you would normally.

See examples/01_simple.py for an example.

Declarative

If you prefer, you can use RichGroup or RichCommand with the cls argument in your click usage instead. This means that you can continue to use the unmodified click package in parallel.

import click
from rich_click import RichCommand

@click.command(cls=RichCommand)
def main():
    """My amazing tool does all the things."""

See examples/02_declarative.py for an example.

rich-click CLI tool

rich-click comes with a CLI tool that allows you to format the Click help output from any package that uses Click.

To use, prefix rich-click to your normal command. For example, to get richified Click help text from a package called awesometool, you could run:

$ rich-click awesometool --help

Usage: awesometool [OPTIONS]
..more richified output below..

License

This project is licensed under the MIT license.

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.