|
9 | 9 | from .profiles import Profile
|
10 | 10 |
|
11 | 11 |
|
| 12 | +def _parse_list_arg(value: str) -> list: |
| 13 | + """Parse a comma-separated or JSON-formatted string into a list""" |
| 14 | + if not value: |
| 15 | + return [] |
| 16 | + |
| 17 | + # Try parsing as JSON first |
| 18 | + if value.startswith("["): |
| 19 | + try: |
| 20 | + import json |
| 21 | + |
| 22 | + return json.loads(value) |
| 23 | + except json.JSONDecodeError: |
| 24 | + pass |
| 25 | + |
| 26 | + # Fall back to comma-separated parsing |
| 27 | + return [item.strip() for item in value.split(",") if item.strip()] |
| 28 | + |
| 29 | + |
12 | 30 | def _profile_to_arg_params(profile: Profile) -> Dict[str, Dict[str, Any]]:
|
13 | 31 | """Convert Profile attributes to argparse parameter definitions"""
|
14 | 32 | return {
|
@@ -54,17 +72,20 @@ def _profile_to_arg_params(profile: Profile) -> Dict[str, Dict[str, Any]]:
|
54 | 72 | "tools": {
|
55 | 73 | "flags": ["--tools"],
|
56 | 74 | "default": profile.tools,
|
57 |
| - "help": "Specify enabled tools (comma-separated)", |
| 75 | + "help": "Specify enabled tools (comma-separated or JSON list)", |
| 76 | + "type": _parse_list_arg, |
58 | 77 | },
|
59 | 78 | "allowed_commands": {
|
60 | 79 | "flags": ["--allowed-commands"],
|
61 | 80 | "default": profile.allowed_commands,
|
62 |
| - "help": "Specify allowed commands", |
| 81 | + "help": "Specify allowed commands (comma-separated or JSON list)", |
| 82 | + "type": _parse_list_arg, |
63 | 83 | },
|
64 | 84 | "allowed_paths": {
|
65 | 85 | "flags": ["--allowed-paths"],
|
66 | 86 | "default": profile.allowed_paths,
|
67 |
| - "help": "Specify allowed paths", |
| 87 | + "help": "Specify allowed paths (comma-separated or JSON list)", |
| 88 | + "type": _parse_list_arg, |
68 | 89 | },
|
69 | 90 | "auto_run": {
|
70 | 91 | "flags": ["--auto-run", "-y"],
|
|
0 commit comments