- introduce InvocationContext and InvocationSegment for styled invocation paths - thread invocation_context through command arg resolution and help/tldr rendering - render CLI and namespace help from routed context instead of static program formatting - support per-segment styling for nested namespaces and command paths - rebase help target context for `help -k` so usage matches the target command path - clean up context module docs and remove old invocation path formatting helper
33 lines
844 B
Python
33 lines
844 B
Python
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass, field
|
|
from enum import Enum
|
|
from typing import TYPE_CHECKING
|
|
|
|
from falyx.context import InvocationContext
|
|
from falyx.namespace import FalyxNamespace
|
|
|
|
if TYPE_CHECKING:
|
|
from falyx.command import Command
|
|
from falyx.falyx import Falyx
|
|
|
|
|
|
class RouteKind(Enum):
|
|
COMMAND = "command"
|
|
NAMESPACE_MENU = "namespace_menu"
|
|
NAMESPACE_HELP = "namespace_help"
|
|
NAMESPACE_TLDR = "namespace_tldr"
|
|
UNKNOWN = "unknown"
|
|
|
|
|
|
@dataclass(slots=True)
|
|
class RouteResult:
|
|
kind: RouteKind
|
|
namespace: "Falyx"
|
|
context: InvocationContext
|
|
command: "Command | None" = None
|
|
namespace_entry: FalyxNamespace | None = None
|
|
leaf_argv: list[str] = field(default_factory=list)
|
|
suggestions: list[str] = field(default_factory=list)
|
|
is_preview: bool = False
|