From 928f874157e955466cc1a272759cbaa126573b64 Mon Sep 17 00:00:00 2001 From: liusongtao Date: Fri, 6 Mar 2026 14:06:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=A4=E4=BB=98=E5=BC=8F=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E7=AE=A1=E7=90=86devel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements_generator/main.py | 127 +++++++++++++++++++++++++-------- 1 file changed, 96 insertions(+), 31 deletions(-) diff --git a/requirements_generator/main.py b/requirements_generator/main.py index dac8c98..049bbf5 100644 --- a/requirements_generator/main.py +++ b/requirements_generator/main.py @@ -665,29 +665,13 @@ def step_patch_signatures_url( # ══════════════════════════════════════════════════════ # Step 2:查询项目 # ══════════════════════════════════════════════════════ - -def step_query_project(non_interactive: bool = False): - console.print("\n[bold]Step 2 · 查询项目[/bold]", style="blue") +def list_projects(): + """以表格形式展示所有项目""" projects = db.list_projects() if not projects: console.print("[red]没有找到任何项目![/red]") return - print_projects(projects) - - if non_interactive: - return - - project_id = Prompt.ask("请输入要查询的项目 ID", default=None) - project = db.get_project_by_id(int(project_id)) - if project: - print_project_details(project) - else: - console.print("[red]项目 ID 不存在![/red]") - - -def print_projects(projects: List[Project]): - """以表格形式展示所有项目""" table = Table(title="📁 项目列表", show_lines=True) table.add_column("ID", style="cyan", width=6) table.add_column("名称", style="magenta", width=20) @@ -699,8 +683,15 @@ def print_projects(projects: List[Project]): console.print(table) -def print_project_details(project: Project): +def print_project_details(project_id = None, non_interactive: bool = False): """打印项目详细信息""" + console.print("\n[bold]Step 3 · 查询项目[/bold]", style="blue") + if project_id is None and non_interactive: + return + if project_id is None: + project_id = Prompt.ask("请输入要查看的项目 ID", default=None) + project = db.get_project_by_id(int(project_id)) + console.print(f"\n[bold]项目详情: {project.name}[/bold]") console.print(f"ID: {project.id}") console.print(f"语言: {project.language}") @@ -725,19 +716,13 @@ def print_project_details(project: Project): # Step 3:删除项目 # ══════════════════════════════════════════════════════ -def step_delete_project(non_interactive: bool = False): +def step_delete_project(project_id = None, non_interactive: bool = False): console.print("\n[bold]Step 3 · 删除项目[/bold]", style="blue") - projects = db.list_projects() - if not projects: - console.print("[red]没有找到任何项目![/red]") + if project_id is None and non_interactive: return - print_projects(projects) - - if non_interactive: - return - - project_id = Prompt.ask("请输入要删除的项目 ID", default=None) + if project_id is None: + project_id = Prompt.ask("请输入要删除的项目 ID", default=None) project = db.get_project_by_id(int(project_id)) if project: if Confirm.ask(f"⚠️ 确认删除项目 '{project.name}' 吗?"): @@ -752,10 +737,17 @@ def step_delete_project(non_interactive: bool = False): # ══════════════════════════════════════════════════════ def step_change_requirements( - project: Project, + project_id = None, non_interactive: bool = False, ) -> List[FunctionalRequirement]: console.print("\n[bold]Step 4 · 变更需求[/bold]", style="blue") + if project_id is None and non_interactive: + return [] + + if project_id is None: + project_id = Prompt.ask("请输入要删除的项目 ID", default=None) + project = db.get_project_by_id(int(project_id)) + func_reqs = db.list_functional_requirements(project.id) if not func_reqs: console.print("[red]没有找到任何功能需求![/red]") @@ -985,6 +977,79 @@ def cli( traceback.print_exc() sys.exit(1) +class ProjectManager: + def __init__(self): + # 初始化项目管理器 + self.projects = {} + self.current_project = None + + def create_project(self): + """创建项目""" + cli() + + def list_projects(self): + """获取项目列表""" + list_projects() + + def delete_project(self, project_id=None): + """删除指定项目""" + step_delete_project(project_id) + + + def view_current_project_info(self): + """查看当前项目信息""" + print_project_details() + + def change_current_project_requirements(self): + """变更当前项目需求""" + step_change_requirements() + + def exit_program(self): + """退出程序""" + sys.exit(0) + + def show_help(self): + """显示帮助菜单""" + help_text = """ + 可用指令: + - create: 创建新项目 + - list : 获取项目列表 + - delete : 删除指定项目 + - view : 查看当前项目信息(需先进入项目) + - change: 变更当前项目需求(需先进入项目) + - quit : 退出程序 + - help : 显示帮助菜单 + """ + print(help_text) + + +def main(): + manager = ProjectManager() + manager.show_help() + while True: + command = input("请输入指令(帮助输入 'help'):") + if command == 'help': + manager.show_help() + elif command.startswith('create'): + manager.create_project() + elif command == 'list': + manager.list_projects() + elif command.startswith('delete'): + try: + _, project_id = command.split(maxsplit=1) + manager.delete_project(int(project_id)) + except: + manager.delete_project() + manager.list_projects() + elif command == 'view': + manager.view_current_project_info() + elif command.startswith('change'): + manager.change_current_project_requirements() + elif command == 'quit': + manager.exit_program() + break + else: + print("未知指令,请重试。") if __name__ == "__main__": - cli() \ No newline at end of file + main() \ No newline at end of file