|
1 | 1 | import typer |
2 | 2 | from rich import print |
3 | 3 |
|
| 4 | +from .interactive_settings import interactive_settings |
4 | 5 | from .settings import set_global_settings |
5 | 6 |
|
6 | 7 |
|
7 | 8 | def config( |
8 | | - key: str = typer.Argument(..., help="setting key"), |
9 | | - value: str = typer.Argument(..., help="setting value"), |
| 9 | + key: str = typer.Argument(None, help="setting key"), |
| 10 | + value: str = typer.Argument(None, help="setting value"), |
| 11 | + *, |
| 12 | + interactive: bool = typer.Option(False, "--interactive", "-i", help="Interactive configuration mode"), |
10 | 13 | ) -> None: |
11 | | - available_keys = ["apiKey", "apiUrl", "model"] |
| 14 | + if interactive or (key is None and value is None): |
| 15 | + interactive_settings() |
| 16 | + return |
| 17 | + |
| 18 | + if key is None or value is None: |
| 19 | + print("Both key and value are required when not using interactive mode") |
| 20 | + print("Use --interactive or -i for interactive configuration") |
| 21 | + raise typer.Exit(1) |
| 22 | + |
| 23 | + available_keys = ["apiKey", "apiUrl", "model", "show_command", "skip_confirm"] |
12 | 24 |
|
13 | 25 | if key not in available_keys: |
14 | | - print(f"Key {key} is not valid") |
| 26 | + print(f"Key {key} is not valid. Available keys: {', '.join(available_keys)}") |
15 | 27 | raise typer.Exit(1) |
16 | 28 |
|
| 29 | + # Convert boolean strings |
| 30 | + if key in ["show_command", "skip_confirm"]: |
| 31 | + if value.lower() in ["true", "1", "yes", "on"]: |
| 32 | + value = True |
| 33 | + elif value.lower() in ["false", "0", "no", "off"]: |
| 34 | + value = False |
| 35 | + else: |
| 36 | + print(f"Invalid boolean value for {key}. Use true/false, 1/0, yes/no, or on/off") |
| 37 | + raise typer.Exit(1) |
| 38 | + |
17 | 39 | set_global_settings(key, value) |
| 40 | + print(f"[green]Setting {key} updated successfully![/green]") |
0 commit comments