Skip to content

Commit 4003997

Browse files
committed
feat: create命令新增交互式选择模板方式
1 parent c79f29d commit 4003997

File tree

5 files changed

+62
-2
lines changed

5 files changed

+62
-2
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ magic-dash list
4242

4343
### 2.2 生成指定项目模板
4444

45+
- ⭐ 推荐:交互式选择项目模板(不指定 `--name` 参数时会弹出选择菜单)
46+
47+
```bash
48+
magic-dash create
49+
```
50+
4551
- 默认生成到当前路径
4652

4753
```bash
@@ -54,6 +60,20 @@ magic-dash create --name magic-dash
5460
magic-dash create --name magic-dash --path 目标路径
5561
```
5662

63+
- 项目生成完成后,进入项目目录运行应用
64+
65+
```bash
66+
cd magic-dash
67+
pip install -r requirements.txt
68+
python app.py
69+
```
70+
71+
- 对于 `magic-dash-pro` 模板,需要额外初始化数据库
72+
73+
```bash
74+
python -m models.init_db
75+
```
76+
5777
### 2.3 查看当前`magic-dash`版本
5878

5979
```bash

magic_dash.egg-info/PKG-INFO

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Description-Content-Type: text/markdown
1212
License-File: LICENSE
1313
Requires-Dist: click
1414
Requires-Dist: rich
15+
Requires-Dist: questionary
1516
Dynamic: author
1617
Dynamic: author-email
1718
Dynamic: classifier

magic_dash.egg-info/requires.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
click
22
rich
3+
questionary

magic_dash/__init__.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import shutil
44

55
import click
6+
import questionary
67
from rich.console import Console
78
from rich.panel import Panel
89
from rich.table import Table
@@ -58,11 +59,47 @@ def _list():
5859

5960

6061
@click.command(name="create")
61-
@click.option("--name", required=True, type=click.STRING, help="Dash应用项目模板名称")
62+
@click.option("--name", type=click.STRING, help="Dash应用项目模板名称")
6263
@click.option("--path", type=click.STRING, default=".", help="项目生成目标路径")
6364
def _create(name, path):
6465
"""生成指定Dash应用项目模板到指定目录"""
6566

67+
custom_style = questionary.Style(
68+
[
69+
("qmark", "fg:#FFD700 bold"),
70+
("question", "bold cyan"),
71+
("answer", "bold green"),
72+
("pointer", "fg:#FFD700 bold"),
73+
("highlighted", "fg:#00FFFF bold"),
74+
("selected", "fg:#00FF00 bold"),
75+
("instruction", "fg:#888"),
76+
]
77+
)
78+
79+
# 如果未指定模板名称,显示交互式选择菜单
80+
if name is None:
81+
choices = [
82+
questionary.Choice(
83+
title=[
84+
("class:highlighted", template_name),
85+
("class:text", f" - {template_info['description']}"),
86+
],
87+
value=template_name,
88+
)
89+
for template_name, template_info in BUILTIN_TEMPLATES.items()
90+
]
91+
92+
name = questionary.select(
93+
"请选择要生成的Dash应用项目模板:",
94+
choices=choices,
95+
style=custom_style,
96+
instruction="(使用方向键选择,回车确认,Esc 取消)",
97+
).ask()
98+
99+
if name is None:
100+
console.print("\n[yellow bold]已取消项目生成[/yellow bold]\n")
101+
return
102+
66103
# 检查目标项目模板是否存在
67104
if name not in BUILTIN_TEMPLATES.keys():
68105
error_msg = (
@@ -104,6 +141,7 @@ def _create(name, path):
104141

105142
# 确认生成
106143
console.print()
144+
console.print("[dim](输入 y 确认,输入 n 取消,直接回车使用默认选项 Y)[/dim]")
107145
if not click.confirm("确认生成项目?", default=True):
108146
console.print("\n[yellow bold]已取消项目生成[/yellow bold]\n")
109147
return

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def get_version():
2929
],
3030
url="https://github.com/CNFeffery/magic-dash",
3131
python_requires=">=3.8, <3.14",
32-
install_requires=["click", "rich"],
32+
install_requires=["click", "rich", "questionary"],
3333
entry_points={
3434
"console_scripts": [
3535
"magic-dash = magic_dash:magic_dash",

0 commit comments

Comments
 (0)