agentleFS
28672032962867203296/hermes-agent/skills/software-development/cli-design/SKILL.md

cli-design

Skill0 starsChanged 3 months agoMITView on GitHub

CLI设计:Click/Typer/argparse、进度条、彩色输出、交互式.

20 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use writing, research and 2 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • alxyrginSkill

    writing

    Создание контента для личного бренда — статьи, посты, туториалы. Use when user asks to "напиши статью", "создай пост", "подготовь контент", "write article", "create content", or when task requires content creation for blogging, LinkedIn, Medium, or other publishing platforms.

    Also in 3 projects that use this

  • NVIDIASkill

    research

    Before designing a feature, research how comparable libraries solve the problem, check best practices, known pitfalls, and upstream changes. Use when starting a new feature, investigating an unfamiliar area, or the user asks to research something.

    Also in 4 projects that use this

  • SentrySkill

    review

    Fixture review skill.

    Also in 3 projects that use this

  • MicrosoftSkill

    handoff

    Compact the current conversation into a handoff document for another agent to pick up.

    Also in 3 projects that use this

The file

Files
SKILL.md

CLI 设计

工具选型

简单脚本 → argparse(标准库)
中等CLI  → Click(装饰器风格)
现代CLI  → Typer(类型注解,基于Click)
超复杂   → argparse + 手动分派

Typer(推荐,最现代)

import typer

app = typer.Typer()

@app.command()
def hello(name: str = "World", count: int = 1):
    """向某人问好"""
    for _ in range(count):
        typer.echo(f"Hello {name}!")

@app.command()
def process(input_file: str, output: str = "output.txt"):
    """处理文件"""
    typer.echo(f"Processing {input_file} -> {output}")

if __name__ == "__main__":
    app()
python cli.py hello --name 郑鑫 --count 3
python cli.py process data.csv -o result.json

Click

import click

@click.group()
def cli():
    pass

@cli.command()
@click.option('--name', default='World', help='名字')
@click.option('--count', default=1, help='次数')
def hello(name, count):
    for _ in range(count):
        click.echo(f'Hello {name}!')

@cli.command()
@click.argument('input_file')
@click.option('-o', '--output', default='output.txt')
def process(input_file, output):
    click.echo(f'Processing {input_file} -> {output}')

进度条

from rich.progress import Progress
import time

with Progress() as progress:
    task = progress.add_task("[cyan]Processing...", total=100)
    for i in range(100):
        time.sleep(0.02)
        progress.update(task, advance=1)

# 或者用 tqdm(最简单)
from tqdm import tqdm
for item in tqdm(items, desc="处理中"):
    process(item)

彩色输出(Rich)

from rich.console import Console
from rich.table import Table

console = Console()
console.print("[green]成功![/green]")
console.print("[red]错误![/red]")
console.print("[bold yellow]警告![/bold yellow]")

# 表格
table = Table(title="用户列表")
table.add_column("ID")
table.add_column("姓名")
table.add_row("1", "郑鑫")
console.print(table)

CLI 设计原则

1. 默认行为合理(不加参数也能跑)
2. --help 清晰完整
3. 错误信息友好(不是堆栈)
4. 进度可观测(进度条/日志)
5. 可组合(管道 | 重定向)
6. 幂等(重复跑不出错)

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.