zilliz 1.4.2

TUI and CLI tool for managing Zilliz Cloud clusters and Milvus operations
Documentation
use anyhow::{Context, Result};

use super::types::CliModel;

const CONTROL_PLANE_JSON: &str = include_str!("builtin_models/control-plane.json");
const DATA_PLANE_JSON: &str = include_str!("builtin_models/data-plane.json");

/// Both models loaded together.
#[derive(Debug, Clone)]
pub struct Models {
    pub control_plane: CliModel,
    pub data_plane: CliModel,
}

pub struct ModelLoader;

impl ModelLoader {
    /// Load the built-in JSON models embedded at compile time.
    pub fn load_builtin() -> Result<Models> {
        let control_plane: CliModel = serde_json::from_str(CONTROL_PLANE_JSON)
            .context("Failed to parse control-plane.json")?;
        let data_plane: CliModel =
            serde_json::from_str(DATA_PLANE_JSON).context("Failed to parse data-plane.json")?;

        // Inherit resource-level dedicated_only to operations
        let control_plane = Self::inherit_dedicated_only(control_plane);
        let data_plane = Self::inherit_dedicated_only(data_plane);

        Ok(Models {
            control_plane,
            data_plane,
        })
    }

    fn inherit_dedicated_only(mut model: CliModel) -> CliModel {
        for resource in model.resources.values_mut() {
            if resource.dedicated_only {
                for op in resource.operations.values_mut() {
                    op.dedicated_only = true;
                }
            }
        }
        model
    }
}