+
+
+ 📋 可用命令 +
+
+
+
命令列表
+
使用示例
+
功能文档
+
+ +
+
+

💡 提示

+

选择一个命令查看详细信息,然后点击"执行命令"按钮运行它。

+
+
    +
  • +
    + 加载命令列表... +
  • +
+
+ +
+
基础示例
+
+import click +from click import interactive_command + +# 简单的交互式命令 +@interactive_command() +@click.option('--name', prompt='你的名字?') +@click.option('--age', type=int, prompt='你的年龄?') +def greet(name, age): + click.echo(f'你好 {name},你 {age} 岁了!') +
+ +
条件提问示例
+
+from click import interactive_option + +@interactive_command() +@click.option('--project-type', + type=click.Choice(['python', 'javascript'])) +@interactive_option( + '--python-version', + interactive_after='project_type', + interactive_condition=lambda params: params.get('project_type') == 'python', + prompt='Python 版本?' +) +@interactive_option( + '--node-version', + interactive_after='project_type', + interactive_condition=lambda params: params.get('project_type') == 'javascript', + prompt='Node.js 版本?' +) +def create_project(project_type, python_version, node_version): + pass +
+
+ +
+
新增功能
+ +
+

🎯 InteractiveCommand

+

支持交互式模式的命令类。当启用时,会自动提示用户输入所有参数。

+
+ +
+

🎯 InteractiveGroup

+

支持交互式菜单的命令组。当没有指定子命令时,显示交互式菜单供用户选择。

+
+ +
+

🎯 InteractiveOption

+

支持条件提问的选项类。可以根据之前的回答决定是否提示该选项。

+
+ +
装饰器
+ +
+

@interactive_command

+

创建交互式命令的装饰器。参数:interactive, interactive_all, interactive_skip

+
+ +
+

@interactive_group

+

创建交互式命令组的装饰器。参数:interactive, interactive_menu

+
+ +
+

@interactive_option

+

创建交互式选项的装饰器。支持条件提问:interactive_when, interactive_after, interactive_condition

+
+
+
+
+ +
+
+ 🚀 命令执行 +
+
+ + +
+
👈
+

请从左侧选择一个命令

+
+ + + + +
+
+