|
34 | 34 | DEFAULT_CONFIG_PATH = os.path.expanduser("~/.dstack-vmm/config.json") |
35 | 35 | DEFAULT_KMS_WHITELIST_PATH = os.path.expanduser("~/.dstack-vmm/kms-whitelist.json") |
36 | 36 |
|
| 37 | + |
37 | 38 | # VMM discovery directories |
38 | 39 | # Each user's instances are in $XDG_RUNTIME_DIR/dstack-vmm (typically /run/user/<uid>/dstack-vmm). |
39 | 40 | # CLI scans all users' directories so operators can see every instance on the host. |
40 | 41 | def _get_discovery_dirs() -> List[Tuple[str, Optional[str]]]: |
41 | 42 | """Return list of (discovery_dir, username) tuples.""" |
42 | 43 | import pwd |
| 44 | + |
43 | 45 | dirs = [] |
44 | 46 | run_user = "/run/user" |
45 | 47 | if os.path.isdir(run_user): |
@@ -180,7 +182,9 @@ def cmd_ls_vmm(args): |
180 | 182 |
|
181 | 183 | if not instances: |
182 | 184 | print("No running VMM instances found.") |
183 | | - print(f" (scanned: {', '.join(d for d, _ in _get_discovery_dirs()) or '/run/user/*/dstack-vmm'})") |
| 185 | + print( |
| 186 | + f" (scanned: {', '.join(d for d, _ in _get_discovery_dirs()) or '/run/user/*/dstack-vmm'})" |
| 187 | + ) |
184 | 188 | return |
185 | 189 |
|
186 | 190 | if getattr(args, "json", False): |
@@ -1560,19 +1564,21 @@ def main(): |
1560 | 1564 |
|
1561 | 1565 | # Register nested subcommands for top-level help display |
1562 | 1566 | _nested_commands = { |
1563 | | - 'vmm ls': 'List all running VMM instances on this host', |
1564 | | - 'vmm switch': 'Switch active VMM instance', |
| 1567 | + "vmm ls": "List all running VMM instances on this host", |
| 1568 | + "vmm switch": "Switch active VMM instance", |
1565 | 1569 | } |
1566 | 1570 |
|
1567 | 1571 | # Patch parser's format_help to show nested subcommands |
1568 | 1572 | _orig_format_help = parser.format_help |
| 1573 | + |
1569 | 1574 | def _patched_format_help(): |
1570 | 1575 | text = _orig_format_help() |
1571 | 1576 | # Append nested subcommands after the subparser listing |
1572 | 1577 | extra = "\nnested commands:\n" |
1573 | 1578 | for cmd, desc in _nested_commands.items(): |
1574 | 1579 | extra += f" {cmd:<24s}{desc}\n" |
1575 | 1580 | return text + extra |
| 1581 | + |
1576 | 1582 | parser.format_help = _patched_format_help |
1577 | 1583 |
|
1578 | 1584 | # List command |
|
0 commit comments