Skip to main content

Reusable CLI kernel for building unified command-line interfaces with consistent behavior, output style, help, and extension semantics.

Project description

cli-core-yo

GitHub Release GitHub Tag License: MIT

Reusable CLI kernel for building unified command-line interfaces with consistent behavior, output style, help, and extension semantics. Built on Typer + Rich.

What It Does

cli-core-yo provides the shared foundation that downstream CLI tools build on:

  • Root app factorycreate_app() builds a fully configured Typer app from a declarative spec
  • Built-in commandsversion, info, and optional config/env groups
  • Plugin system — explicit callables + cli_core_yo.plugins entry-point discovery
  • XDG paths — platform-aware config/data/state/cache directory resolution (macOS + Linux)
  • Output primitivesheading, success, warning, error, action, detail, bullet, emit_json
  • Runtime context — immutable singleton accessible to all commands during invocation
  • JSON mode--json/-j flag with deterministic output (indent=2, sorted keys, no ANSI)
  • NO_COLOR — respects the NO_COLOR convention
  • Debug modeCLI_CORE_YO_DEBUG=1 prints tracebacks to STDERR

Prerequisites

  • Python 3.10+
  • pip

Installation

pip install cli-core-yo

For development:

git clone https://github.com/Daylily-Informatics/cli-core-yo.git
cd cli-core-yo
pip install -e ".[dev]"

Quick Start

from cli_core_yo.spec import CliSpec, XdgSpec
from cli_core_yo.app import run

spec = CliSpec(
    prog_name="my-tool",
    app_display_name="My Tool",
    dist_name="my-tool",
    root_help="A CLI built with cli-core-yo.",
    xdg=XdgSpec(vendor="my-tool"),
)

exit_code = run(spec)

This gives you my-tool version, my-tool info, my-tool --help, --json support, and all the standard behaviors out of the box.

Adding Commands via Plugin

# my_tool/plugin.py
def register(registry, spec):
    registry.add_command(None, "greet", greet_cmd, help_text="Say hello.")

def greet_cmd():
    from cli_core_yo import output
    output.success("Hello, world!")

Register it in your spec:

from cli_core_yo.spec import PluginSpec

spec = CliSpec(
    ...,
    plugins=PluginSpec(explicit=["my_tool.plugin.register"]),
)

Or via entry points in pyproject.toml:

[project.entry-points."cli_core_yo.plugins"]
my-tool = "my_tool.plugin:register"

Config & Env Groups

Enable optional built-in command groups by providing specs:

from cli_core_yo.spec import ConfigSpec, EnvSpec

spec = CliSpec(
    ...,
    config=ConfigSpec(
        primary_filename="config.json",
        template_bytes=b'{"key": "value"}\n',
    ),
    env=EnvSpec(
        env_dir_name=".venv",
        activate_script_rel="bin/activate",
    ),
)

This adds config path|init|show|validate|edit|reset and env status|activate|deactivate|reset.

Public API

Symbol Module Description
create_app(spec) cli_core_yo.app Build a Typer app from a CliSpec
run(spec, argv) cli_core_yo.app Execute CLI, return exit code (never calls sys.exit())
CommandRegistry cli_core_yo.registry Register commands/groups with ordering and conflict detection
get_context() cli_core_yo.runtime Access the current invocation's RuntimeContext
CliSpec, ConfigSpec, EnvSpec, PluginSpec, XdgSpec cli_core_yo.spec Frozen dataclass specs
output.* cli_core_yo.output UX primitives + emit_json()

HTTPS Certificate Resolution

cli_core_yo.certs now supports a shared HTTPS resolution contract for downstream services. The resolve_https_certs() helper applies this precedence order:

  1. explicit CLI-provided cert and key paths
  2. generic SSL_CERT_FILE / SSL_KEY_FILE
  3. service-specific legacy env vars supplied by the caller
  4. an existing shared certificate directory
  5. an existing repo-local fallback certificate directory
  6. optional mkcert generation, preferring the shared directory

For Dayhoff-managed local deployments, shared_dayhoff_certs_dir(deploy_name) resolves the canonical shared directory under XDG state:

~/.local/state/dayhoff/<deploy-name>/certs/

Exit Codes

Code Meaning
0 Success
1 Domain/runtime failure
2 Usage error (bad args, unknown command)
130 SIGINT

Build / Test / Lint

# Run tests
python -m pytest tests/ -v --cov=cli_core_yo

# Lint + format check
ruff check cli_core_yo tests
ruff format --check cli_core_yo tests

# Type check
mypy cli_core_yo --ignore-missing-imports

# Build distribution
python -m build
twine check dist/*

License

MIT — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cli_core_yo-1.0.0.tar.gz (40.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cli_core_yo-1.0.0-py3-none-any.whl (23.6 kB view details)

Uploaded Python 3

File details

Details for the file cli_core_yo-1.0.0.tar.gz.

File metadata

  • Download URL: cli_core_yo-1.0.0.tar.gz
  • Upload date:
  • Size: 40.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for cli_core_yo-1.0.0.tar.gz
Algorithm Hash digest
SHA256 509371072a15e6008db702003c9524b5aeaf43b146e3949c6428b861be323d1e
MD5 f2fe4d588c79575077cfefe5874ae511
BLAKE2b-256 fd07d1e2eb4068d9d2514e8201fcbed85e6ec013bf972ea4dd020f4a1cad50a0

See more details on using hashes here.

File details

Details for the file cli_core_yo-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: cli_core_yo-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 23.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for cli_core_yo-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d4383e4b2ab9317eab0c9cbdf7f7d93107f78feb9ebb5b9da0528a4f49ae9e68
MD5 b7ca0e0f1755497ca0315e9c6c1fe1cb
BLAKE2b-256 378d069c16562c3cd4b0aa3b510a57531aeccdbcfd0119b5a675a9f57e14a0ed

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page