Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:20000419 Fauxnix Command Dispatch Registry

From Leeroopedia
Knowledge Sources
Domains Command_Dispatch, Code_Generation
Last Updated 2026-10-26 00:00 GMT

Overview

A command-dispatch technique that maps each source-shell command name to a generator function via a registry, with shared helpers for strict option validation and string escaping, so the translator can emit correct target-language code per command.

Description

The Command Dispatch Registry is the bridge between the parsed AST and the per-command code generators. A Map<string, Handler> maps bash command names to generator functions that return a block of PowerShell statements following the Fauxnix contract. The registry is populated at import time; lookup(name) retrieves the generator; unknown names fall through to native pass-through execution. Shared helpers enforce consistency: psStr (PowerShell string escaping), psErr/psErr2 (bash-style stderr line + exit-flag), parseArgs/parseWords (word-preserving argv parsing with bundled flags and value-taking options), and CommandSpec (strict GNU-style option validation that fails on unknown options rather than silently ignoring them).

Usage

Use this principle when a source-to-source translator must handle many commands, each with its own option set and output format. The registry + shared-helpers pattern keeps generators consistent and independently testable.

Theoretical Basis

registry = Map<name, (args, ctx) => psBlock>
register(name, handler); registerAll(module)
lookup(name) → handler | undefined

# translator:
handler = lookup(cmd.name)
if handler: psBlock = handler(cmd.args, {position, hasStdin, translationMode})
else: passthrough (native argv execution)

Related Pages

Implemented By

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment