跳到主要内容
知仓学习社ZHICANG

reviewing-cli-command

Provides checklist for reviewing Typer CLI command implementations. Covers structure, Annotated syntax, error handling, exit codes, display module u…

不碰外部(只输出文字)无严重或高危命中https-deeplearning-ai/sc-agent-skills-files

它会碰到什么

扫了多少1 个文本文件,3 KB
它会碰到什么不碰外部(只输出文字)
命中总数0 处
命中统计严重 0 · 高 0 · 中 0 · 低 0

这一栏是扫描器报的事实,不是结论。命中多不等于有毒(安全工具、规则库、示例脚本本来就会包含危险写法),命中少也不等于干净。它和你手上的凭据、文件、网络有什么关系,需要你自己看。

技能内容

Reviewing CLI Commands

Checklist for reviewing Typer CLI command implementations.

Review Process

  1. Read the command file
  2. Check each section below
  3. Report findings using output format at bottom

Structure

  • [ ] File in src/<cli_app>/commands/
  • [ ] Has app = typer.Typer() and @app.command()
  • [ ] Command groups use @app.command() for each subcommand
  • [ ] Registered in commands/__init__.py with add_typer()
  • [ ] Single commands: add_typer(app) without name
  • [ ] Command groups: add_typer(app, name="group")

Arguments & Options

  • [ ] Uses Annotated syntax
  • [ ] Arguments for required positional input
  • [ ] Options for optional named parameters
  • [ ] Short flags where appropriate (-f, -q)
  • [ ] Help text: lowercase, no period, brief
# GOOD:
name: Annotated[str, typer.Argument(help="item name")]
force: Annotated[bool, typer.Option("--force", "-f", help="skip confirmation")] = False

# BAD:
name: str = typer.Argument(..., help="The name of the item.")

Error Handling

  • [ ] Validates input before processing
  • [ ] Exit codes: 0=success, 1=error, 2=invalid input
  • [ ] Errors via display.error()
  • [ ] Uses raise typer.Exit(code) after errors
  • [ ] Uses raise typer.Abort() for cancellation
# GOOD:
if id < 1:
    display.error("ID must be positive")
    raise typer.Exit(EXIT_INVALID_INPUT)

# BAD:
if id < 1:
    print("Error: ID must be positive")
    return

Output

  • [ ] All output through display module
  • [ ] No print(), typer.echo(), or console.print()
# GOOD:
display.success(f"Added '{task.title}'")

# BAD:
print(f"Added '{task.title}'")

Destructive Actions

  • [ ] Has --force / -f flag
  • [ ] typer.confirm() with default=False
  • [ ] Shows "Cancelled" on abort
# GOOD:
if not force:
    confirm = typer.confirm(f"Delete '{task.title}'?", default=False)
    if not confirm:
        display.info("Cancelled")
        raise typer.Abort()

# BAD: defaults to Yes
confirm = typer.confirm(f"Delete?", default=True)

Help Text

  • [ ] Docstring exists
  • [ ] Imperative mood ("Add a task" not "Adds a task")
  • [ ] First line < 60 characters

Common Mistakes

| Mistake | Fix |

|---------|-----|

| print() | display.success/error/warning/info() |

| Wrong exit code | 0=success, 1=error, 2=invalid |

| Missing --force on delete | Add force option with default False |

| Confirmation defaults Yes | default=False in typer.confirm() |

| Old Typer syntax | Annotated[type, typer.Argument()] |

| Missing app = typer.Typer() | Each command file needs its own app |

| Not registered | add_typer(app) in commands/__init__.py |

Review Output Format

## Review: <command_name>

[OK] Uses Annotated syntax
[OK] Has docstring in imperative mood
[X] Missing --force flag on destructive command
[X] Uses print() instead of display module
[!] Help text could be shorter

### Summary
<brief summary of issues found>

### Suggested Fixes
<code suggestions if needed>

想直接用这个技能?

本站把开放许可(MIT / Apache 等)的技能按仓库打包整理到网盘,点一下转存到你自己的网盘,不用一个个从 GitHub 拉。许可未声明的技能只给原始仓库链接,不打包。