euv-cli 0.46.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::*;

/// CLI target selector covering all 23 supported euv platforms plus `native` and `all`.
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, ValueEnum)]
pub enum TargetArg {
    /// Browser WebAssembly target (`wasm32-unknown-unknown`).
    Web,
    /// Android native NDK target (`aarch64-linux-android`).
    Android,
    /// iOS native UIKit/Metal target (`aarch64-apple-ios`).
    Ios,
    /// iPadOS native UIKit/Metal target (`aarch64-apple-ios`).
    Ipad,
    /// macOS native AppKit/Metal target (`aarch64-apple-darwin` / `x86_64-apple-darwin`).
    Macos,
    /// Windows native Win32/D3D12 target (`x86_64-pc-windows-msvc` / `aarch64-pc-windows-msvc`).
    Windows,
    /// Linux native Wayland/X11/Vulkan target (`x86_64-unknown-linux-gnu` / `aarch64-unknown-linux-gnu`).
    Linux,
    /// Interactive PTY Terminal UI target.
    Tui,
    /// Non-interactive static/pipe CLI terminal target.
    Cli,
    /// Google/Samsung Wear OS smartwatch target.
    Wearos,
    /// Apple watchOS smartwatch target.
    Watchos,
    /// Huawei HarmonyOS Watch wearable target.
    #[value(name = "harmony-wearable")]
    HarmonyWearable,
    /// Xiaomi HyperOS / Vela Watch wearable target.
    Vela,
    /// Generic smart wearable target (OPPO / vivo / Garmin / ZeppOS).
    Wearable,
    /// HarmonyOS / OpenHarmony multi-form-factor native target (phone/tablet/pc/foldable/tv/car).
    Harmony,
    /// WeChat Mini-Program target (`wx`).
    Wechat,
    /// Alipay Mini-Program target (`my`).
    Alipay,
    /// Douyin / ByteDance Mini-Program target (`tt`).
    Douyin,
    /// Baidu Smart Mini-Program target (`swan`).
    Baidu,
    /// QQ Mini-Program target (`qq`).
    Qq,
    /// Kuaishou Mini-Program target (`ks`).
    Kuaishou,
    /// HarmonyOS Atomic Service target (`atomic`).
    #[value(name = "harmony-atomic")]
    HarmonyAtomic,
    /// QuickApp Alliance / Huawei QuickApp target.
    Quickapp,
    /// Current host native target.
    Native,
    /// Every supported euv platform.
    All,
}

/// Optional HarmonyOS / OpenHarmony device form factor selector for `euv build --target harmony`.
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize, ValueEnum)]
pub enum HarmonyFormFactorArg {
    /// HarmonyOS phone device profile.
    #[default]
    Phone,
    /// HarmonyOS tablet device profile.
    Tablet,
    /// HarmonyOS PC / 2-in-1 desktop device profile.
    Pc,
    /// HarmonyOS foldable display device profile.
    Foldable,
    /// HarmonyOS smart TV / Vision device profile.
    Tv,
    /// HarmonyOS automotive / cockpit device profile.
    Car,
    /// HarmonyOS smartwatch wearable device profile.
    Wearable,
}

/// CLI render pipeline mode selector.
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, ValueEnum)]
pub enum RenderArg {
    /// Automatically prefer hardware GPU with software fallback.
    Auto,
    /// Deterministic software CPU rasterizer.
    Software,
    /// Native GPU instanced pipeline.
    Hardware,
    /// Hybrid CPU vector + GPU texture compositor.
    Hybrid,
}

/// Target mode for the `euv dev` hot-reload and OTA development server.
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, ValueEnum)]
pub enum DevTargetArg {
    /// Build and live-reload all project Markdown documentation pages.
    Docs,
    /// Build and live-reload WebAssembly zero-JS bundles plus Dynamic WASM OTA feed.
    Web,
    /// Watch Rust sources, rebuild, hot-restart the native app, and serve Dynamic WASM OTA updates.
    Native,
    /// Watch Rust sources and relaunch interactive PTY Terminal UI builds.
    Tui,
    /// Watch Rust sources and rerun static/pipe CLI terminal builds.
    Cli,
    /// Watch Rust sources and rebuild HarmonyOS HAP bundles.
    Harmony,
    /// Watch Rust sources and rebuild wearable smartwatch bundles.
    Wearable,
    /// Watch Rust sources and rebuild Mini-Program bundles.
    Miniapp,
    /// Watch Rust sources and rebuild QuickApp bundles.
    Quickapp,
}

/// Subcommands under `euv docs` for building or live-serving project Markdown documentation.
#[derive(Clone, Debug, Eq, PartialEq, Subcommand)]
pub enum DocsAction {
    /// Builds all Markdown files under a project or docs directory into a static site.
    Build {
        /// Shared source, output, title, and base URL flags.
        #[command(flatten)]
        build: DocsBuildArgs,
    },
    /// Builds and serves Markdown documentation with live file-watching and SSE hot reload.
    Dev {
        /// Shared source, output, title, and base URL flags.
        #[command(flatten)]
        build: DocsBuildArgs,
        /// Shared dev server bind, poll interval, and smoke-run flags.
        #[command(flatten)]
        server: ServerBindArgs,
    },
}

/// Subcommands under `euv update` for operating the Hyperlane HTTP + SSE dynamic update server and local store.
#[derive(Clone, Debug, Eq, PartialEq, Subcommand)]
pub enum UpdateAction {
    /// Starts the read-only Hyperlane HTTP + SSE dynamic update server backed by the local store directory.
    Serve {
        /// Local update store root directory (`staging/`, `blobs/`, `releases/`, `channels/`, `state/`).
        #[arg(long, default_value = DEFAULT_UPDATE_STORE_DIR)]
        store: PathBuf,
        /// Host bind address.
        #[arg(long, default_value = DEFAULT_UPDATE_SERVER_HOST)]
        host: String,
        /// TCP listen port (`0` selects an ephemeral port).
        #[arg(long, default_value_t = DEFAULT_UPDATE_SERVER_PORT)]
        port: u16,
        /// SSE keep-alive heartbeat interval in milliseconds.
        #[arg(long, default_value_t = DEFAULT_UPDATE_HEARTBEAT_MS)]
        heartbeat_ms: u64,
        /// Background channel pointer watcher polling interval in milliseconds.
        #[arg(long, default_value_t = DEFAULT_UPDATE_WATCH_POLL_MS)]
        poll_ms: u64,
        /// Validate store layout and server bind readiness then exit immediately.
        #[arg(long, default_value_t = false)]
        once: bool,
        /// Print the structured server configuration without binding sockets.
        #[arg(long, default_value_t = false)]
        plan: bool,
    },
    /// Stages and SHA-256-verifies a release manifest and its blobs into `staging/<stage_id>/`.
    Stage {
        /// Local update store root directory.
        #[arg(long, default_value = DEFAULT_UPDATE_STORE_DIR)]
        store: PathBuf,
        /// Logical project identifier.
        #[arg(long)]
        project: String,
        /// Release channel name (e.g. `prod`).
        #[arg(long)]
        channel: String,
        /// Unique stage identifier name.
        #[arg(long)]
        stage_id: String,
        /// Path to the draft JSON `ReleaseManifest` file.
        #[arg(long)]
        manifest: PathBuf,
        /// Directory containing built artifact blobs referenced by `manifest`.
        #[arg(long)]
        blobs_dir: PathBuf,
    },
    /// Atomically signs and publishes a staged release with a strictly monotonic sequence number.
    Publish {
        /// Local update store root directory.
        #[arg(long, default_value = DEFAULT_UPDATE_STORE_DIR)]
        store: PathBuf,
        /// Logical project identifier.
        #[arg(long)]
        project: String,
        /// Release channel name.
        #[arg(long)]
        channel: String,
        /// Previously staged directory name under `staging/`.
        #[arg(long)]
        stage_id: String,
        /// Offline HMAC-SHA256 signing secret (or provide `--signing-key-env`).
        #[arg(long)]
        signing_key: Option<String>,
        /// Environment variable name holding the offline signing secret.
        #[arg(long, default_value = ENV_UPDATE_SIGNING_KEY)]
        signing_key_env: String,
    },
    /// Signs a NEW monotonic release pointing back to a historical release's verified blobs (never replaying old manifests).
    Rollback {
        /// Local update store root directory.
        #[arg(long, default_value = DEFAULT_UPDATE_STORE_DIR)]
        store: PathBuf,
        /// Logical project identifier.
        #[arg(long)]
        project: String,
        /// Release channel name.
        #[arg(long)]
        channel: String,
        /// Historical release sequence whose verified artifacts should be restored.
        #[arg(long)]
        to_release: u64,
        /// Offline HMAC-SHA256 signing secret (or provide `--signing-key-env`).
        #[arg(long)]
        signing_key: Option<String>,
        /// Environment variable name holding the offline signing secret.
        #[arg(long, default_value = ENV_UPDATE_SIGNING_KEY)]
        signing_key_env: String,
    },
    /// Inspects active channel pointers, release counts, and content-addressed blob inventory in a local update store.
    Status {
        /// Local update store root directory.
        #[arg(long, default_value = DEFAULT_UPDATE_STORE_DIR)]
        store: PathBuf,
        /// Optional project filter.
        #[arg(long)]
        project: Option<String>,
        /// Optional channel filter.
        #[arg(long)]
        channel: Option<String>,
    },
}

/// Top-level `euv` CLI subcommands.
#[derive(Clone, Debug, Eq, PartialEq, Subcommand)]
pub enum Commands {
    /// Runs an euv application for a target platform and render mode, with optional `--watch` hot reload.
    Run {
        /// Target platform to launch.
        #[arg(long, value_enum, default_value_t = TargetArg::Native)]
        target: TargetArg,
        /// Optional HarmonyOS form factor (`phone`, `tablet`, `pc`, `foldable`, `tv`, `car`, `wearable`).
        #[arg(long, value_enum, default_value_t = HarmonyFormFactorArg::Phone)]
        form_factor: HarmonyFormFactorArg,
        /// Rendering pipeline mode.
        #[arg(long, value_enum, default_value_t = RenderArg::Auto)]
        render: RenderArg,
        /// Build and run in release mode.
        #[arg(long, default_value_t = false)]
        release: bool,
        /// Optional Cargo package name to run.
        #[arg(long)]
        package: Option<String>,
        /// Enable file-watching hot reload and live OTA update serving.
        #[arg(short = 'w', long, default_value_t = false)]
        watch: bool,
        /// HTTP hot-reload/OTA port when `--watch` is enabled.
        #[arg(long, default_value_t = 8080)]
        port: u16,
        /// Print the execution plan without spawning Cargo.
        #[arg(long, default_value_t = false)]
        plan: bool,
    },
    /// Starts the hot-reload and Dynamic WASM OTA development server for Web, Native, Docs, Terminal, Harmony, Wearable, MiniApp, or QuickApp.
    Dev {
        /// Development pipeline target (`web`, `native`, `docs`, `tui`, `cli`, `harmony`, `wearable`, `miniapp`, `quickapp`).
        #[arg(long, value_enum, default_value_t = DevTargetArg::Web)]
        target: DevTargetArg,
        /// Rendering pipeline mode default.
        #[arg(long, value_enum, default_value_t = RenderArg::Auto)]
        render: RenderArg,
        /// Build and serve in release mode when rebuilding Web or Native targets.
        #[arg(long, default_value_t = false)]
        release: bool,
        /// Optional project root directory to watch (defaults to current directory).
        #[arg(long)]
        path: Option<PathBuf>,
        /// Optional output directory for built bundles.
        #[arg(long)]
        out: Option<PathBuf>,
        /// Optional Cargo package name to rebuild on changes.
        #[arg(long)]
        package: Option<String>,
        /// Shared dev server bind, poll interval, and smoke-run flags.
        #[command(flatten)]
        server: ServerBindArgs,
        /// Enable live Dynamic WASM OTA manifest + `.wasm` hot-update endpoint (`--ota=false` disables).
        #[arg(long, default_value_t = true, num_args = 0..=1, default_missing_value = "true")]
        ota: bool,
        /// Print the structured dev server plan without spawning processes.
        #[arg(long, default_value_t = false)]
        plan: bool,
    },
    /// Manages the Hyperlane HTTP + SSE dynamic update server and atomic local release store (`serve`, `stage`, `publish`, `rollback`, `status`).
    Update {
        /// Dynamic update server or store management subcommand.
        #[command(subcommand)]
        action: UpdateAction,
    },
    /// Builds or live-serves a static documentation site from all `.md` files in a project.
    Docs {
        /// Optional `build` or `dev` subcommand (defaults to building all project `.md` files).
        #[command(subcommand)]
        action: Option<DocsAction>,
        /// Shared source, output, title, and base URL flags.
        #[command(flatten)]
        build: DocsBuildArgs,
        /// Enable live watch and SSE hot-reload dev server directly from `euv docs --watch`.
        #[arg(short = 'w', long, default_value_t = false)]
        watch: bool,
        /// Shared dev server bind, poll interval, and smoke-run flags when `--watch` is active.
        #[command(flatten)]
        server: ServerBindArgs,
    },
    /// Builds native, terminal, wearable, HarmonyOS, Mini-Program, QuickApp, or Web bundles for one or all targets.
    Build {
        /// Target platform (or `all`).
        #[arg(long, value_enum, default_value_t = TargetArg::Native)]
        target: TargetArg,
        /// Optional HarmonyOS device form factor (`phone`, `tablet`, `pc`, `foldable`, `tv`, `car`, `wearable`).
        #[arg(long, value_enum, default_value_t = HarmonyFormFactorArg::Phone)]
        form_factor: HarmonyFormFactorArg,
        /// Rendering pipeline mode default.
        #[arg(long, value_enum, default_value_t = RenderArg::Auto)]
        render: RenderArg,
        /// Enable release optimization profile.
        #[arg(long, default_value_t = false)]
        release: bool,
        /// Print structured JSON build plans without executing.
        #[arg(long, default_value_t = false)]
        plan: bool,
    },
    /// Checks Rust compilation across one or all cross-platform targets.
    Check {
        /// Check all supported platform targets in sequence.
        #[arg(long, default_value_t = false)]
        all_targets: bool,
        /// Single target to check when `--all-targets` is omitted.
        #[arg(long, value_enum, default_value_t = TargetArg::Native)]
        target: TargetArg,
        /// Optional Cargo package name to check.
        #[arg(long)]
        package: Option<String>,
        /// Print the planned commands without running Cargo.
        #[arg(long, default_value_t = false)]
        plan: bool,
    },
    /// Runs unified `crate-cli` text/Rust formatting first, then normalizes indentation inside all `euv` macro blocks (`view!`, `style!`, etc.).
    Fmt {
        /// Verify formatting without modifying files.
        #[arg(long, default_value_t = false)]
        check: bool,
        /// Optional root directory or file path (defaults to current directory).
        #[arg(long)]
        path: Option<PathBuf>,
        /// Format only `euv` procedural macro bodies without invoking `crate-cli` or `cargo fmt`.
        #[arg(long, default_value_t = false)]
        macros_only: bool,
    },
    /// Inspects installed Rust targets, SDKs, and cross-platform tooling readiness.
    Doctor {
        /// Emit machine-readable JSON output.
        #[arg(long, default_value_t = false)]
        json: bool,
    },
    /// Scaffolds a new cross-platform euv native project.
    New {
        /// Name of the new project directory and crate.
        name: String,
        /// Optional parent directory (defaults to current working directory).
        #[arg(long)]
        path: Option<PathBuf>,
    },
}