moon_config 2.0.13

Core workspace, project, and moon configuration.
Documentation
// NOTE: This is used by toolchain plugins, and not moon directly!

use crate::{config_enum, config_struct, is_false};
use schematic::{Config, validate};

config_struct!(
    /// Configures to a tool-specific global binary to install.
    #[derive(Config)]
    pub struct BinConfig {
        /// Name of the binary, with optional version separated by `@`.
        #[setting(validate = validate::not_empty)]
        pub bin: String,

        /// Force install the binary if it already exists.
        #[serde(default, skip_serializing_if = "is_false")]
        pub force: bool,

        /// Only install the binary locally, and not within CI.
        #[serde(default, skip_serializing_if = "is_false")]
        pub local: bool,

        /// For supported tools, a custom name to use.
        #[serde(default, skip_serializing_if = "Option::is_none")]
        pub name: Option<String>,
    }
);

config_enum!(
    /// Configures to a tool-specific global binary to install.
    #[derive(Config)]
    #[serde(untagged)]
    pub enum BinEntry {
        /// Name of the binary to install.
        String(String),

        /// Expanded configuration for the binary to install.
        #[setting(nested)]
        Object(BinConfig),
    }
);

impl BinEntry {
    pub fn get_name(&self) -> &str {
        match self {
            BinEntry::String(name) => name,
            BinEntry::Object(cfg) => &cfg.bin,
        }
    }
}