//! Types for the `before_serve` configuration and `exec_aliases` table. //! //! Lives outside `config.rs` so the latter stays under the 500-line limit //! the project enforces (see AGENTS.md). use serde::Deserialize; /// Behaviour on a non-zero exit code for a [`PreServeCommand`]. #[derive(Clone, Copy, Debug, PartialEq, Eq, Default, Deserialize)] #[serde(rename_all = "lowercase")] pub enum OnFailure { /// Abort the serve (default). #[default] Abort, /// Log a warning but continue. Warn, /// Continue silently. Continue, } /// One entry in a `before_serve` block. Either a bare command string /// (defaults to `on_failure = abort`) or a table with explicit `on_failure`. #[derive(Clone, Debug, Deserialize)] #[serde(untagged)] pub enum PreServeCommand { Bare(String), Configured { command: String, #[serde(default)] on_failure: OnFailure, }, } impl PreServeCommand { pub fn command(&self) -> &str { match self { PreServeCommand::Bare(c) => c, PreServeCommand::Configured { command, .. } => command, } } pub fn on_failure(&self) -> OnFailure { match self { PreServeCommand::Bare(_) => OnFailure::default(), PreServeCommand::Configured { on_failure, .. } => *on_failure, } } } /// TOML sub-table under `[before_serve.""]`. Currently only /// carries `commands`; reserved for future per-cluster tuning. #[derive(Clone, Debug, Default, Deserialize)] pub struct BeforeServeTable { #[serde(default)] pub commands: Vec, }