huge refactor of the entire codebase, with the goal of improving maintainability, readability, and extensibility. This commit includes changes to almost every file in the project, including:
This commit is contained in:
+15
-15
@@ -7,7 +7,7 @@ from . import _shared as sh
|
||||
from SYS.logger import log
|
||||
from SYS import pipeline as ctx
|
||||
|
||||
from SYS.result_table_adapters import get_provider
|
||||
from SYS.result_table_adapters import get_plugin
|
||||
from SYS.result_table_renderers import RichRenderer
|
||||
|
||||
Cmdlet = sh.Cmdlet
|
||||
@@ -16,19 +16,19 @@ parse_cmdlet_args = sh.parse_cmdlet_args
|
||||
|
||||
|
||||
CMDLET = Cmdlet(
|
||||
name="provider-table",
|
||||
summary="Render a provider's result set and optionally run a follow-up cmdlet using the selected row.",
|
||||
usage="provider-table -provider <name> [-sample] [-select <n>] [-run-cmd <name>]",
|
||||
name="plugin-table",
|
||||
summary="Render a plugin's result set and optionally run a follow-up cmdlet using the selected row.",
|
||||
usage="plugin-table -plugin <name> [-sample] [-select <n>] [-run-cmd <name>]",
|
||||
arg=[
|
||||
CmdletArg("provider", type="string", description="Provider name to render (default: example)"),
|
||||
CmdletArg("sample", type="flag", description="Use provider sample/demo items when available."),
|
||||
CmdletArg("plugin", type="string", description="Plugin name to render (default: example)"),
|
||||
CmdletArg("sample", type="flag", description="Use plugin sample/demo items when available."),
|
||||
CmdletArg("select", type="int", description="1-based row index to select and use for follow-up command."),
|
||||
CmdletArg("run-cmd", type="string", description="Cmdlet to invoke with the selected row's selector args."),
|
||||
],
|
||||
detail=[
|
||||
"Use a registered provider to build a table and optionally run another cmdlet with selection args.",
|
||||
"Use a registered plugin to build a table and optionally run another cmdlet with selection args.",
|
||||
"Emits pipeline-friendly dicts enriched with `_selection_args` so you can use @N syntax to select and chain.",
|
||||
"Example: provider-table -provider example -sample | @1 | add-file -store my_store",
|
||||
"Example: plugin-table -plugin example -sample | @1 | add-file -store my_store",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -36,15 +36,15 @@ CMDLET = Cmdlet(
|
||||
def _run(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
parsed = parse_cmdlet_args(args, CMDLET)
|
||||
|
||||
provider_name = parsed.get("provider") or "example"
|
||||
plugin_name = parsed.get("plugin") or "example"
|
||||
use_sample = bool(parsed.get("sample", False))
|
||||
run_cmd = parsed.get("run-cmd")
|
||||
select_raw = parsed.get("select")
|
||||
|
||||
try:
|
||||
provider = get_provider(provider_name)
|
||||
provider = get_plugin(plugin_name)
|
||||
except Exception:
|
||||
log(f"Unknown provider: {provider_name}", file=sys.stderr)
|
||||
log(f"Unknown plugin: {plugin_name}", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
# Obtain items to feed to the adapter
|
||||
@@ -55,23 +55,23 @@ def _run(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
mod = __import__(provider.adapter.__module__, fromlist=["*"])
|
||||
items = getattr(mod, "SAMPLE_ITEMS", None)
|
||||
if items is None:
|
||||
log("Provider does not expose SAMPLE_ITEMS; no sample available", file=sys.stderr)
|
||||
log("Plugin does not expose SAMPLE_ITEMS; no sample available", file=sys.stderr)
|
||||
return 1
|
||||
except Exception:
|
||||
log("Failed to load provider sample", file=sys.stderr)
|
||||
log("Failed to load plugin sample", file=sys.stderr)
|
||||
return 1
|
||||
else:
|
||||
# Require input for non-sample runs
|
||||
inputs = list(result) if isinstance(result, Iterable) else []
|
||||
if not inputs:
|
||||
log("No input provided. Use -sample for demo or pipe provider items in.", file=sys.stderr)
|
||||
log("No input provided. Use -sample for demo or pipe plugin items in.", file=sys.stderr)
|
||||
return 1
|
||||
items = inputs
|
||||
|
||||
try:
|
||||
table = provider.build_table(items)
|
||||
except Exception as exc:
|
||||
log(f"Provider '{provider.name}' failed: {exc}", file=sys.stderr)
|
||||
log(f"Plugin '{provider.name}' failed: {exc}", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
# Emit rows for downstream pipeline consumption (pipable behavior).
|
||||
|
||||
Reference in New Issue
Block a user