Skip to main content
The palyra-cli crate provides the operator interface for managing both local and remote Palyra runtimes. It is built using a layered architecture that resolves configuration, handles profile-based guardrails, and dispatches commands to specialized modules.

CLI Dispatch Lifecycle

The entry point for the CLI is the run function in crates/palyra-cli/src/lib.rs. It follows a deterministic lifecycle to ensure environment consistency before any command logic executes.
  1. Argument Parsing: Uses clap to parse argv into the Cli struct crates/palyra-cli/src/lib.rs#3-5.
  2. Context Resolution: The RootCommandContext is initialized, resolving the active profile, state root, and configuration path crates/palyra-cli/src/app/mod.rs#45-58.
  3. Guardrail Validation: If a command is executed with --expect-profile, the CLI verifies the resolved profile matches before proceeding crates/palyra-cli/src/args/mod.rs#79-80.
  4. Command Dispatch: The CliCommand enum fans out to specific modules under commands/ crates/palyra-cli/src/lib.rs#115-130.

CLI Dispatch Flow

This diagram illustrates the transition from the OS entry point to the internal command handlers. Sources: crates/palyra-cli/src/lib.rs#1-15, crates/palyra-cli/src/app/mod.rs#41-58

RootContext and Global Options

The RootCommandContext is the source of truth for every CLI invocation. It encapsulates formatting, logging, and connection defaults crates/palyra-cli/src/app/mod.rs#45-58.
OptionCode ReferenceDescription
--profileRootOptions::profileSelects a named connection profile from cli/profiles.toml crates/palyra-cli/src/app/mod.rs#139-147.
--configRootOptions::configExplicit path to palyra.toml crates/palyra-cli/src/app/mod.rs#49.
--state-rootRootOptions::state_rootDirectory for durable state (logs, DBs, keys) crates/palyra-cli/src/app/mod.rs#46-48.
--output-formatOutputFormatArgSupports text, json, and ndjson crates/palyra-cli/src/args/mod.rs#97-102.
Sources: crates/palyra-cli/src/app/mod.rs#41-70, crates/palyra-cli/src/args/mod.rs#75-113

Profile Guardrails and Strict Mode

Palyra implements “Profile Guardrails” to prevent accidental operations on production environments. Profiles are stored in a registry located at cli/profiles.toml within the state root crates/palyra-cli/src/app/mod.rs#139-147. Sources: crates/palyra-cli/src/app/mod.rs#151-173, crates/palyra-cli/src/args/mod.rs#109-113

Gateway and Daemon Commands

The gateway (aliased as daemon) family provides administrative control over the palyrad process. It communicates via the Admin HTTP API and gRPC surfaces crates/palyra-cli/src/commands/daemon.rs#3-5.

Service Lifecycle Management

Sources: crates/palyra-cli/src/support/service.rs#1-40, crates/palyra-cli/src/commands/daemon.rs#1-10

The Doctor Diagnostic System

The doctor command is a comprehensive diagnostic engine that identifies and repairs environment issues. It operates on a “Check and Report” model crates/palyra-cli/src/commands/doctor.rs#1-10.
  1. Check Discovery: Aggregates checks for filesystem permissions, configuration validity, network connectivity, and security posture crates/palyra-cli/src/commands/security.rs#118-123.
  2. Snapshot Generation: Captures the current state into a HealthResponse crates/palyra-common/src/health.rs#45-48.
  3. Repair Logic: Provides remediation steps or executes automatic repairs when the --repair flag is present crates/palyra-cli/src/args/mod.rs#42.
The security audit command extends the Doctor system by ranking findings into blocking, warning, and info severities crates/palyra-cli/src/commands/security.rs#23-48. Sources: crates/palyra-cli/src/commands/doctor.rs#1-10, crates/palyra-cli/src/commands/security.rs#115-163, crates/palyra-common/src/health.rs#45-48

Config and State Commands

The CLI provides tools to inspect and mutate the local environment without manual file editing. Sources: crates/palyra-cli/src/commands/config.rs#1-10, crates/palyra-common/src/config_system.rs#136-141, crates/palyra-cli/tests/config_validate.rs#1-10