Skip to main content

hexastack-cli

hexastack-cli

Typer and Rich presentation adapter for Hexastack: nested commands, aliases, piped outputs, and CQRS dispatching.

PyPI: hexastack-cli Python 3.13+ Coverage Part of Hexastack Governed by Hexaqual License: Apache 2.0

Part of the Hexastack Framework · Governed by Hexaqual.


1. Overview & Capabilities

hexastack-cli turns Hexastack CQRS commands and queries into intuitive, modern CLI applications:

  • Nested Command Hierarchies: Nest subcommands naturally (app user create, app db migrate) using @cli_group.
  • Command Aliases: Register multiple aliases for the same action (app user new == app user create).
  • Typo Tolerance & Suggestions (TyperSuggest): Drop-in replacement for typer.Typer that intercepts unrecognized subcommands or flags, computes closest matches via Levenshtein distance, prompts interactively for confirmation, and exits cleanly in CI/non-interactive pipelines.
  • Feature Flag Gating: Gate CLI commands dynamically with @feature_flag_command(...) and @cli_command(..., feature_flag=...).
  • Rich Formatted & CI-Friendly Output: Beautiful tables, panels, and spinners for interactive terminals; clean text/JSON streaming for CI/CD pipelines.
  • Direct CQRS Dispatching: Declaratively expose domain commands (@cli_command) and queries (@cli_query) with automatic parameter parsing and validation.
  • Automated Demo Narration & Slicing (CliNarrator): Headless terminal recording generating asciinema streams, high-resolution .webm videos, chapterized .checkpoint_segment() flushes, and synchronized .vtt subtitles.

2. Package Anatomy & Key Components

hexastack_cli/
├── domain/          # CliContext, OutputFormat enum
├── adapters/        # Rich presenters, Typer command runners, TyperSuggest
└── infra/           # create_cli_app, CliBootstrapper (order=40), @cli_command, @cli_query, @cli_group, @feature_flag_command

Key Exports

Category Exports
Application Factory & Typo Tolerance create_cli_app, TyperSuggest, SuggestGroup, SuggestCommand, CliBootstrapper (order=40)
Decorators @cli_command, @cli_query, @cli_group, @feature_flag_command
Presenters RichTerminalPresenter, ConsolePresenter, TablePresenter, JsonPresenter
Testing & Demo Narration CliNarrator, TerminalEvent

3. Monorepo & Sibling Relationships

graph TD
    subgraph UserInvocation ["CLI Invocations"]
        INV["Terminal Commands & Scripts"]
    end

    subgraph CliLayer ["hexastack-cli"]
        TYPER["Typer Application (Nested Groups & Aliases)"]
        RICH["Rich Presenters (Tables, Panels, JSON)"]
        SCAN["CLI Decorator Scanner (@cli_command, @cli_query)"]
    end

    subgraph CQRSExecution ["hexastack-cqrs"]
        CBUS["CommandBusPort"]
        QBUS["QueryBusPort"]
    end

    subgraph Kernel ["hexastack-core"]
        DI["rodi.Container"]
    end

    INV --> TYPER
    TYPER --> SCAN
    SCAN -->|dispatches to| CBUS
    SCAN -->|dispatches to| QBUS
    SCAN --> RICH

    TYPER -. resolves buses from DI .-> DI

Explicit Dependencies (Direct)

  • hexastack-core: Core kernel, DI container, and ports.
  • hexastack-cqrs: CommandBusPort and QueryBusPort for message dispatching.
  • typer>=0.27.1: CLI command parser and shell completion.
  • rich>=15.0.0: Terminal formatting, tables, and colors.

Implied / Behavioral Relationships (DI-Mediated)

  • CQRS Integration: Dispatches CLI argument payloads directly into the application's command and query buses.
  • Umbrella CLI: Consumed by the hexastack umbrella package to power diagnostic commands (hexastack info, hexastack inspect registry, hexastack demo ping).

4. Installation

# Standalone install
pip install hexastack-cli

# Via umbrella package
pip install "hexastack[cli]"

5. Quickstart Example

from dataclasses import dataclass
from hexastack_core.infra.bootstrap import bootstrap
from hexastack_cqrs.domain.query import Query
from hexastack_cqrs.infra.decorators import query_handler
from hexastack_cli.infra.decorators import cli_query, cli_group


@dataclass(frozen=True)
class CheckStatusQuery(Query):
    service_name: str


@query_handler(CheckStatusQuery)
class CheckStatusHandler:
    def __call__(self, qry: CheckStatusQuery) -> dict:
        return {"service": qry.service_name, "status": "ONLINE"}


# Expose query as a CLI command
cli_query("status", aliases=["st", "health"], help="Check status of a service")(
    CheckStatusQuery
)

runtime = bootstrap(packages_to_scan=[__name__])
cli_app = runtime.get("cli_app")

6. Standalone Typo-Tolerant CLI (TyperSuggest)

TyperSuggest is a drop-in replacement for typer.Typer. It intercepts mistyped commands and options, presenting suggestions and interactive confirmations without throwing cryptic syntax errors:

from hexastack_cli.adapters import TyperSuggest

app = TyperSuggest(help="My Resilient Service CLI")


@app.command()
def deploy(environment: str = "staging", force: bool = False):
    print(f"Deploying to {environment} (force={force})")


if __name__ == "__main__":
    app()
$ python cli.py deply
Unrecognized command 'deply'. Did you mean 'deploy'? [y/N]: y
Deploying to staging (force=False)

$ python cli.py deploy --frc
Unrecognized option '--frc'. Did you mean '--force'? [y/N]: y
Deploying to staging (force=True)

In automated CI environments or redirected streams (not sys.stdin.isatty()), TyperSuggest prints the suggested correction to stderr and exits cleanly with error code 2 without hanging.


7. Automated Demo Recording & Video Slicing (CliNarrator)

Automated narrative terminal recording and Playwright demo video rendering is provided by hexaqual.adapters.testing.

from hexaqual.adapters.testing import CliNarrator

narrator = CliNarrator(record_video=True)
narrator.say("Scaffolding microservice...")
narrator.run("hexastack new web-api billing-service")

# Flush Chapter 1 video & VTT segment
narrator.checkpoint_segment("ch01-scaffolding")

narrator.say("Applying SQLite database migrations...")
narrator.run("hexastack db migrate")

# Flush Chapter 2 video & VTT segment
narrator.checkpoint_segment("ch02-migrations")

Metadata

Release files for hexastack-cli 0.10.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hexastack-cli 0.10.1
File Size Uploaded Provenance Actions
hexastack_cli-0.10.1.tar.gz 20.0 kB Without provenance Details for hexastack_cli-0.10.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hexastack-cli 0.10.1
File Interpreter ABI Platform Actions
hexastack_cli-0.10.1-py3-none-any.whl Python 3 none any Details for hexastack_cli-0.10.1-py3-none-any.whl

Total release size: 45.2 kB

Release files / hexastack_cli-0.10.1.tar.gz

Download URL hexastack_cli-0.10.1.tar.gz
Size 20.0 kB
Tags Source
SHA-256 checksum
How to use checksums
85700e45d4be769e68ef762ac2956bf082c0b488bb1303ebb3ce07a19a4efa40
BLAKE2b-256 checksum
How to use checksums
0069b040adc1f9be3298a9bf189ff821447132e9b7704644f780efc30f16339e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / hexastack_cli-0.10.1-py3-none-any.whl

Download URL hexastack_cli-0.10.1-py3-none-any.whl
Size 25.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d9ee0cbf7f870f22387fe96f776cc59bc3ebda7c461efb251ed501a4eeb33212
BLAKE2b-256 checksum
How to use checksums
4c603e8c9a7652bdad2e0db2f7c0b776f23532ee6cb67b396e51751444a946f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for hexastack-cli 0.10.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page