click README

The project's README from github.com/pallets/click. As one markdown file: README.md.

Click

Click is a Python package for creating beautiful command line interfaces in a composable way with as little code as necessary. It's the "Command Line Interface Creation Kit". It's highly configurable but comes with sensible defaults out of the box.

It aims to make the process of writing command line tools quick and fun while also preventing any frustration caused by the inability to implement an intended CLI API.

Click in three points:

A Simple Example

import 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 hello.py --count=3
Your name: Click
Hello, Click!
Hello, Click!
Hello, Click!

Donate

The Pallets organization develops and supports Click and other popular packages. In order to grow the community of contributors and users, and allow the maintainers to devote more time to the projects, please donate today.

Contributing

See our detailed contributing documentation for many ways to contribute, including reporting issues, requesting features, asking or answering questions, and making PRs.

click (pallets/click)

Searching Database…

17.8K ·GitHub
这是什么东西?Click 是一个 Python 包,用来以组合的方式构建美观的命令行界面,所需代码量极少。它的名字是 'Command Line Interface Creation Kit'(命令行界面创建工具包)的缩写。
它是我在终端里运行的工具,还是我写代码时用的库?它是一个库,不是应用程序:你把它导入到自己的 Python 项目里,用它编写代码来创建你自己的命令行程序。
我怎么把它加到我的项目里?先用 pip 安装('pip install click'),然后在你的 Python 代码里导入它,开始定义命令;这个工具包会围绕这些命令自动组装出命令行界面。
除了 Python 解释器,我还需要别的东西吗?不需要。它是一个普通的 pip 包,没有任何必需的服务或系统依赖,任何能运行 Python 的机器都可以使用。
我必须是 Python 开发者才能用它吗?是的,它是给构建命令行工具的开发者用的,从单命令小工具到大型的多命令程序都可以;运行这些成品工具的人完全接触不到 Click 本身。
它在 Windows 和 macOS 上能用吗,还是只支持 Linux?只要能运行 Python 的地方都能用。该项目列出了 Windows、macOS 和 Linux,而且作为一个纯 Python 的 pip 包,它本身就是跨平台的。
用 Click 构建时,开箱即能得到什么?你的命令的帮助页面会自动生成,而且这个工具包虽然高度可配置,但自带合理的默认值,所以只需写很少的代码就能做出一个像样的命令行工具。
我的工具会有很多子命令,Click 能应付吗?能。它支持任意层级的命令嵌套,还可以在运行时延迟加载子命令,因此大型命令行程序既能保持条理,启动也快。
这是个新出的实验项目,还是成熟的老项目?是成熟项目:开发始于 2014 年,在 GitHub 上有约 17.8k 颗星。它由 Pallets 组织开发和维护,该组织同时维护其他流行的包,并接受捐款来支持维护工作。
和手动写参数解析相比,为什么选 Click?这正是它诞生的初衷:它的目标是让编写命令行工具变得快捷有趣,避免你实现不出自己想要的 CLI API 时的挫败感。
Creator
pallets
Size
5 MB
Stars
17.8K
Age
12y
Commits · 90 Days