This commit is contained in:
2026-02-11 19:06:38 -08:00
parent 1d0de1118b
commit ba623cb992
20 changed files with 848 additions and 247 deletions

View File

@@ -4,7 +4,7 @@ from typing import Any, Dict, Sequence, List, Optional, Tuple
import shlex
import sys
from cmdlet._shared import Cmdlet, CmdletArg, parse_cmdlet_args
from SYS.cmdlet_spec import Cmdlet, CmdletArg, parse_cmdlet_args
from cmdlet import REGISTRY as CMDLET_REGISTRY, ensure_cmdlet_modules_loaded
from SYS.logger import log
from SYS.result_table import Table
@@ -16,6 +16,8 @@ def _normalize_choice_list(arg_names: Optional[List[str]]) -> List[str]:
_HELP_EXAMPLE_SOURCE_COMMAND = ".help-example"
_METADATA_CACHE_KEY: Optional[Tuple[int, int]] = None
_METADATA_CACHE_VALUE: Optional[Tuple[Dict[str, Dict[str, Any]], Dict[str, str]]] = None
def _example_for_cmd(name: str) -> List[str]:
@@ -104,6 +106,13 @@ def _build_alias_map_from_metadata(metadata: Dict[str, Dict[str, Any]]) -> Dict[
def _gather_metadata_from_cmdlet_classes() -> Tuple[Dict[str, Dict[str, Any]], Dict[str, str]]:
global _METADATA_CACHE_KEY, _METADATA_CACHE_VALUE
cache_key = (len(sys.modules), len(CMDLET_REGISTRY))
if _METADATA_CACHE_KEY == cache_key and _METADATA_CACHE_VALUE is not None:
cached_metadata, cached_alias = _METADATA_CACHE_VALUE
return dict(cached_metadata), dict(cached_alias)
metadata: Dict[str, Dict[str, Any]] = {}
alias_map: Dict[str, str] = {}
try:
@@ -116,7 +125,7 @@ def _gather_metadata_from_cmdlet_classes() -> Tuple[Dict[str, Dict[str, Any]], D
if not (mod_name.startswith("cmdlet.") or mod_name == "cmdlet" or mod_name.startswith("cmdnat.")):
continue
cmdlet_obj = getattr(module, "CMDLET", None)
if not isinstance(cmdlet_obj, Cmdlet):
if cmdlet_obj is None or not hasattr(cmdlet_obj, "name") or not hasattr(cmdlet_obj, "arg"):
continue
canonical_key = _normalize_cmdlet_key(getattr(cmdlet_obj, "name", None) or "")
if not canonical_key:
@@ -166,6 +175,9 @@ def _gather_metadata_from_cmdlet_classes() -> Tuple[Dict[str, Dict[str, Any]], D
},
)
_METADATA_CACHE_KEY = cache_key
_METADATA_CACHE_VALUE = (dict(metadata), dict(alias_map))
return metadata, alias_map