|
1 | 1 | import logging |
2 | | -from itertools import groupby |
3 | 2 |
|
4 | 3 | import rich |
5 | 4 | import rich_click as click |
6 | 5 | from rich.table import Table |
7 | 6 |
|
8 | | -from codegen.shared.configs.constants import CODEGEN_DIR_NAME, ENV_FILENAME, GLOBAL_ENV_FILE |
| 7 | +from codegen.shared.configs.constants import ENV_FILENAME, GLOBAL_ENV_FILE |
9 | 8 | from codegen.shared.configs.session_manager import session_manager |
10 | 9 | from codegen.shared.configs.user_config import UserConfig |
11 | 10 |
|
@@ -43,14 +42,39 @@ def flatten_dict(data: dict, prefix: str = "") -> dict: |
43 | 42 | table.add_column("Key", style="cyan", no_wrap=True) |
44 | 43 | table.add_column("Value", style="magenta") |
45 | 44 |
|
46 | | - # Group by prefix (before underscore) |
47 | | - def get_prefix(item): |
48 | | - return item[0].split("_")[0] |
| 45 | + # Group items by prefix |
| 46 | + codebase_items = [] |
| 47 | + repository_items = [] |
| 48 | + other_items = [] |
| 49 | + |
| 50 | + for key, value in sorted_items: |
| 51 | + prefix = key.split("_")[0].lower() |
| 52 | + if prefix == "codebase": |
| 53 | + codebase_items.append((key, value)) |
| 54 | + elif prefix == "repository": |
| 55 | + repository_items.append((key, value)) |
| 56 | + else: |
| 57 | + other_items.append((key, value)) |
| 58 | + |
| 59 | + # Add codebase section |
| 60 | + if codebase_items: |
| 61 | + table.add_section() |
| 62 | + table.add_row("[bold yellow]Codebase[/bold yellow]", "") |
| 63 | + for key, value in codebase_items: |
| 64 | + table.add_row(f" {key}", str(value)) |
| 65 | + |
| 66 | + # Add repository section |
| 67 | + if repository_items: |
| 68 | + table.add_section() |
| 69 | + table.add_row("[bold yellow]Repository[/bold yellow]", "") |
| 70 | + for key, value in repository_items: |
| 71 | + table.add_row(f" {key}", str(value)) |
49 | 72 |
|
50 | | - for prefix, group in groupby(sorted_items, key=get_prefix): |
| 73 | + # Add other section |
| 74 | + if other_items: |
51 | 75 | table.add_section() |
52 | | - table.add_row(f"[bold yellow]{prefix.title()}[/bold yellow]", "") |
53 | | - for key, value in group: |
| 76 | + table.add_row("[bold yellow]Other[/bold yellow]", "") |
| 77 | + for key, value in other_items: |
54 | 78 | table.add_row(f" {key}", str(value)) |
55 | 79 |
|
56 | 80 | rich.print(table) |
@@ -91,13 +115,13 @@ def set_command(key: str, value: str, is_global: bool): |
91 | 115 | rich.print(f"[red]{e}[/red]") |
92 | 116 | return |
93 | 117 |
|
94 | | - rich.print(f"[green]Successfully set {key}=[magenta]{value}[/magenta] and saved to .env[/green]") |
| 118 | + rich.print(f"[green]Successfully set {key}=[magenta]{value}[/magenta] and saved to {ENV_FILENAME}[/green]") |
95 | 119 |
|
96 | 120 |
|
97 | 121 | def _get_user_config(is_global: bool) -> UserConfig: |
98 | 122 | if is_global or (active_session_path := session_manager.get_active_session()) is None: |
99 | 123 | env_filepath = GLOBAL_ENV_FILE |
100 | 124 | else: |
101 | | - env_filepath = active_session_path / CODEGEN_DIR_NAME / ENV_FILENAME |
| 125 | + env_filepath = active_session_path / ENV_FILENAME |
102 | 126 |
|
103 | 127 | return UserConfig(env_filepath) |
0 commit comments