Expand description
§Inbound Ports — Driving the Application
Inbound ports define how external systems can drive the fernctl application. They are the entry points through which configuration is loaded, validated, and queried.
§Overview
┌─────────────────────────────────────────────────────────────┐
│ DRIVING ADAPTERS │
│ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ TomlAdapter │ │ CliAdapter │ │ JsonAdapter │ │
│ │ │ │ │ │ │ │
│ │ Reads .toml │ │ Parses args │ │ Reads .json │ │
│ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │
│ │ │ │ │
└──────────┼─────────────────┼─────────────────┼──────────────┘
│ │ │
╔═════╧═════════════════╧═════════════════╧═════════════╗
║ INBOUND PORTS ║
║ ║
║ ConfigPort ──────► Load raw configuration ║
║ ValidatePort ────► Validate and transform ║
║ QueryPort ───────► Query theme values ║
║ ║
╚═══════════════════════════╤═══════════════════════════╝
│
▼
┌──────────────┐
│ DOMAIN │
│ Theme │
│ Tokens │
└──────────────┘§Port Responsibilities
| Port | Responsibility | Input | Output |
|---|---|---|---|
ConfigPort | Load raw configuration | Source (file content, path) | Raw config data |
ValidatePort | Validate and transform | Raw config | Validated theme |
QueryPort | Query theme values | Theme + query | Token values |
§Usage Pattern
Inbound ports are typically used in this sequence:
ⓘ
use fernctl::ports::inbound::*;
use fernctl::adapters::TomlConfigAdapter;
// 1. Load raw configuration
let config_adapter = TomlConfigAdapter::new();
let raw_config = config_adapter.load_from_file("config.toml")?;
// 2. Validate and transform
let theme = raw_config.validate()?.into_theme();
// 3. Query values (optional)
let bg_color = query_adapter.get_color(&theme, "background")?;§Implementing Custom Adapters
To add support for a new configuration format (e.g., YAML):
ⓘ
use fernctl::ports::inbound::ConfigPort;
use fernctl::domain::config::RawConfig;
use fernctl::error::Result;
struct YamlConfigAdapter;
impl ConfigPort for YamlConfigAdapter {
fn load(&self, source: &str) -> Result<RawConfig> {
// Parse YAML and convert to RawConfig
let yaml: serde_yaml::Value = serde_yaml::from_str(source)?;
RawConfig::from_yaml(yaml)
}
fn format_name(&self) -> &'static str {
"YAML"
}
}Structs§
- Config
Warning - A non-fatal warning from configuration validation.
- RawConfig
- Raw configuration data before validation.
- Validated
Config - Configuration that has passed validation.
Enums§
- Source
Format - The format a configuration was parsed from.
Traits§
- Config
Port - Port for loading configuration from external sources.
- Query
Port - Port for querying theme values.
- Validate
Port - Port for validating configuration data.