|
14 | 14 | from urllib.request import urlopen |
15 | 15 |
|
16 | 16 | from rich.console import Console |
17 | | -from rich.prompt import Confirm |
| 17 | +from rich.prompt import Confirm, Prompt |
18 | 18 |
|
19 | 19 | from .events import ( |
20 | 20 | send_event, |
@@ -512,56 +512,78 @@ def setup_cursor(console: Console, local_path: pathlib.Path | None = None) -> No |
512 | 512 | SETUP_HANDLERS = {"claude-code": setup_claude_code, "cursor": setup_cursor} |
513 | 513 |
|
514 | 514 |
|
515 | | -def handle_setup_command(args, console: Console) -> None: |
516 | | - """Handle the setup command with its subcommands.""" |
517 | | - available_tools = ", ".join(SETUP_HANDLERS) |
518 | | - ctx = create_event_context() |
| 515 | +def prompt_tool_selection(console: Console) -> list[str]: |
| 516 | + """Prompt the user to select which tool(s) to set up. |
519 | 517 |
|
520 | | - if args.tool is None: |
521 | | - console.print("[bold red]Error:[/] Please specify a tool to set up.") |
522 | | - console.print(f"Available tools: {available_tools}") |
523 | | - console.print("\nUsage: weco setup <tool>") |
524 | | - sys.exit(1) |
| 518 | + Returns: |
| 519 | + List of tool names to set up. |
| 520 | + """ |
| 521 | + tool_names = list(SETUP_HANDLERS.keys()) |
| 522 | + all_option = len(tool_names) + 1 |
525 | 523 |
|
526 | | - handler = SETUP_HANDLERS.get(args.tool) |
527 | | - if handler is None: |
528 | | - console.print(f"[bold red]Error:[/] Unknown tool: {args.tool}") |
529 | | - console.print(f"Available tools: {available_tools}") |
530 | | - sys.exit(1) |
| 524 | + console.print("\n[bold cyan]Available tools to set up:[/]\n") |
| 525 | + for i, name in enumerate(tool_names, 1): |
| 526 | + console.print(f" {i}. {name}") |
| 527 | + console.print(f" {all_option}. All of the above") |
| 528 | + |
| 529 | + valid_choices = [str(i) for i in range(1, all_option + 1)] |
| 530 | + choice = Prompt.ask("\n[bold]Select an option[/]", choices=valid_choices, show_choices=True) |
| 531 | + |
| 532 | + idx = int(choice) |
| 533 | + if idx == all_option: |
| 534 | + return tool_names |
| 535 | + return [tool_names[idx - 1]] |
531 | 536 |
|
532 | | - # Extract local path if provided |
533 | | - local_path = None |
534 | | - if hasattr(args, "local") and args.local: |
535 | | - local_path = pathlib.Path(args.local).expanduser().resolve() |
536 | 537 |
|
537 | | - # Determine source type for event reporting |
| 538 | +def _run_setup_for_tool(tool: str, console: Console, local_path: pathlib.Path | None, ctx) -> None: |
| 539 | + """Run setup for a single tool with event tracking and error handling.""" |
538 | 540 | source = "local" if local_path else "download" |
539 | 541 |
|
540 | | - # Send skill install started event |
541 | | - send_event(SkillInstallStartedEvent(tool=args.tool, source=source), ctx) |
| 542 | + send_event(SkillInstallStartedEvent(tool=tool, source=source), ctx) |
542 | 543 |
|
543 | 544 | start_time = time.time() |
544 | 545 |
|
545 | 546 | try: |
| 547 | + handler = SETUP_HANDLERS[tool] |
546 | 548 | handler(console, local_path=local_path) |
547 | 549 |
|
548 | | - # Send successful completion event |
549 | 550 | duration_ms = int((time.time() - start_time) * 1000) |
550 | | - send_event(SkillInstallCompletedEvent(tool=args.tool, source=source, duration_ms=duration_ms), ctx) |
| 551 | + send_event(SkillInstallCompletedEvent(tool=tool, source=source, duration_ms=duration_ms), ctx) |
551 | 552 |
|
552 | 553 | except DownloadError as e: |
553 | | - # Send failure event |
554 | | - send_event(SkillInstallFailedEvent(tool=args.tool, source=source, error_type="download_error", stage="download"), ctx) |
| 554 | + send_event(SkillInstallFailedEvent(tool=tool, source=source, error_type="download_error", stage="download"), ctx) |
555 | 555 | console.print(f"[bold red]Error:[/] {e}") |
556 | 556 | sys.exit(1) |
557 | 557 | except SafetyError as e: |
558 | | - # Send failure event |
559 | | - send_event(SkillInstallFailedEvent(tool=args.tool, source=source, error_type="safety_error", stage="setup"), ctx) |
| 558 | + send_event(SkillInstallFailedEvent(tool=tool, source=source, error_type="safety_error", stage="setup"), ctx) |
560 | 559 | console.print(f"[bold red]Safety Error:[/] {e}") |
561 | 560 | sys.exit(1) |
562 | 561 | except (SetupError, FileNotFoundError, OSError, ValueError) as e: |
563 | | - # Send failure event |
564 | 562 | error_type = type(e).__name__ |
565 | | - send_event(SkillInstallFailedEvent(tool=args.tool, source=source, error_type=error_type, stage="setup"), ctx) |
| 563 | + send_event(SkillInstallFailedEvent(tool=tool, source=source, error_type=error_type, stage="setup"), ctx) |
566 | 564 | console.print(f"[bold red]Error:[/] {e}") |
567 | 565 | sys.exit(1) |
| 566 | + |
| 567 | + |
| 568 | +def handle_setup_command(args, console: Console) -> None: |
| 569 | + """Handle the setup command with its subcommands.""" |
| 570 | + ctx = create_event_context() |
| 571 | + |
| 572 | + if args.tool is None: |
| 573 | + selected_tools = prompt_tool_selection(console) |
| 574 | + else: |
| 575 | + handler = SETUP_HANDLERS.get(args.tool) |
| 576 | + if handler is None: |
| 577 | + available_tools = ", ".join(SETUP_HANDLERS) |
| 578 | + console.print(f"[bold red]Error:[/] Unknown tool: {args.tool}") |
| 579 | + console.print(f"Available tools: {available_tools}") |
| 580 | + sys.exit(1) |
| 581 | + selected_tools = [args.tool] |
| 582 | + |
| 583 | + # Extract local path if provided |
| 584 | + local_path = None |
| 585 | + if hasattr(args, "local") and args.local: |
| 586 | + local_path = pathlib.Path(args.local).expanduser().resolve() |
| 587 | + |
| 588 | + for tool in selected_tools: |
| 589 | + _run_setup_for_tool(tool, console, local_path, ctx) |
0 commit comments