euv-cli 0.50.0

Cross-platform CLI tool for the euv native UI framework supporting run, build, check, fmt, doctor, new, and Hyperlane SSE dynamic updates across all supported platforms.
Documentation
use super::*;

/// Target metadata and CI release naming helpers for `DesktopTargetKind`.
impl DesktopTargetKind {
    /// Returns the desktop target matching the current host operating system.
    ///
    /// # Returns
    ///
    /// - `Self` - `Macos`, `Windows`, or `Linux` based on `cfg!(target_os)`.
    #[must_use]
    pub fn current_host() -> Self {
        if cfg!(target_os = "macos") {
            Self::Macos
        } else if cfg!(target_os = "windows") {
            Self::Windows
        } else {
            Self::Linux
        }
    }

    /// Maps a CLI `TargetArg` into a `DesktopTargetKind` when supported.
    ///
    /// # Arguments
    ///
    /// - `TargetArg` - Parsed CLI target selector.
    ///
    /// # Returns
    ///
    /// - `Option<Self>` - Matching desktop/terminal target kind or `None` for non-desktop targets.
    #[must_use]
    pub fn from_target_arg(target: TargetArg) -> Option<Self> {
        match target {
            TargetArg::Macos => Some(Self::Macos),
            TargetArg::Windows => Some(Self::Windows),
            TargetArg::Linux => Some(Self::Linux),
            TargetArg::Tui => Some(Self::Tui),
            TargetArg::Cli => Some(Self::Cli),
            TargetArg::Native => Some(Self::current_host()),
            _ => None,
        }
    }

    /// Returns the canonical lowercase platform label (`macos`, `windows`, `linux`, `tui`, `cli`).
    ///
    /// # Arguments
    ///
    /// - `&Self` - Desktop target kind.
    ///
    /// # Returns
    ///
    /// - `&'static str` - Canonical lowercase platform label.
    #[must_use]
    pub fn platform_label(&self) -> &'static str {
        match self {
            Self::Macos => DESKTOP_LABEL_MACOS,
            Self::Windows => DESKTOP_LABEL_WINDOWS,
            Self::Linux => DESKTOP_LABEL_LINUX,
            Self::Tui => DESKTOP_LABEL_TUI,
            Self::Cli => DESKTOP_LABEL_CLI,
        }
    }

    /// Returns the default architecture label matching CI release naming (`arm64` or `x86_64`).
    ///
    /// # Arguments
    ///
    /// - `&Self` - Desktop target kind.
    ///
    /// # Returns
    ///
    /// - `&'static str` - Architecture label string.
    #[must_use]
    pub fn default_arch(&self) -> &'static str {
        match self {
            Self::Macos => DESKTOP_ARCH_ARM64,
            Self::Windows | Self::Linux => DESKTOP_ARCH_X86_64,
            Self::Tui | Self::Cli => {
                if cfg!(target_arch = "aarch64") {
                    DESKTOP_ARCH_ARM64
                } else {
                    DESKTOP_ARCH_X86_64
                }
            }
        }
    }

    /// Returns the platform executable suffix (`".exe"` on Windows, `""` otherwise).
    ///
    /// # Arguments
    ///
    /// - `&Self` - Desktop target kind.
    ///
    /// # Returns
    ///
    /// - `&'static str` - Executable filename suffix.
    #[must_use]
    pub fn exe_suffix(&self) -> &'static str {
        match self {
            Self::Windows => DESKTOP_EXE_SUFFIX_WINDOWS,
            Self::Tui | Self::Cli if cfg!(target_os = "windows") => DESKTOP_EXE_SUFFIX_WINDOWS,
            _ => "",
        }
    }

    /// Returns the default CI archive extension (`"zip"` on Windows, `"tar.gz"` on Unix).
    ///
    /// # Arguments
    ///
    /// - `&Self` - Desktop target kind.
    ///
    /// # Returns
    ///
    /// - `&'static str` - Archive extension without leading dot.
    #[must_use]
    pub fn default_archive_ext(&self) -> &'static str {
        match self {
            Self::Windows => DESKTOP_ARCHIVE_EXT_ZIP,
            Self::Tui | Self::Cli if cfg!(target_os = "windows") => DESKTOP_ARCHIVE_EXT_ZIP,
            _ => DESKTOP_ARCHIVE_EXT_TAR_GZ,
        }
    }

    /// Returns the default staging directory path (`dist/client-<platform>`).
    ///
    /// # Arguments
    ///
    /// - `&Self` - Desktop target kind.
    ///
    /// # Returns
    ///
    /// - `PathBuf` - Default output directory path.
    #[must_use]
    pub fn default_out_dir(&self) -> PathBuf {
        PathBuf::from(format!("{DESKTOP_OUT_DIR_PREFIX}{}", self.platform_label()))
    }

    /// Returns the canonical GitHub Release asset filename (`euv-<version>-<platform>-<arch>.<ext>`).
    ///
    /// # Arguments
    ///
    /// - `&Self` - Desktop target kind.
    /// - `&str` - Semantic version string.
    ///
    /// # Returns
    ///
    /// - `String` - Exact CI release asset filename.
    #[must_use]
    pub fn default_release_asset_name(&self, version: &str) -> String {
        format!(
            "{DESKTOP_CLI_BIN_NAME}-{version}-{}-{}.{}",
            self.platform_label(),
            self.default_arch(),
            self.default_archive_ext()
        )
    }

    /// Returns the native platform icon filename when this target expects a staged icon.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Desktop target kind.
    ///
    /// # Returns
    ///
    /// - `Option<&'static str>` - Icon filename (`euv.icns`, `euv.ico`, `euv.png`) or `None` for terminal targets.
    #[must_use]
    pub fn icon_filename(&self) -> Option<&'static str> {
        match self {
            Self::Macos => Some(DESKTOP_ICON_MACOS),
            Self::Windows => Some(DESKTOP_ICON_WINDOWS),
            Self::Linux => Some(DESKTOP_ICON_LINUX),
            Self::Tui | Self::Cli => None,
        }
    }
}

/// Default configuration targeting the current host desktop platform in release mode.
impl Default for DesktopBuildConfig {
    /// Constructs a release `DesktopBuildConfig` for the current host platform.
    ///
    /// # Returns
    ///
    /// - `Self` - Default desktop build configuration.
    fn default() -> Self {
        let host_target: DesktopTargetKind = DesktopTargetKind::current_host();
        Self {
            repo_root: PathBuf::from("."),
            target: host_target,
            package: None,
            target_triple: None,
            out_dir: host_target.default_out_dir(),
            archive_path: None,
            icon_path: None,
            version: None,
            features: Vec::new(),
            release: true,
            include_cli: false,
            smoke: false,
            verify_ai_schema: true,
        }
    }
}