proto_schema_plugin/
schema.rs

1use serde::Deserialize;
2use std::collections::HashMap;
3
4#[derive(Debug, Default, Deserialize)]
5#[serde(default, rename_all = "kebab-case")]
6pub struct PlatformMapper {
7    pub archive_prefix: Option<String>,
8    pub bin_path: Option<String>,
9    pub checksum_file: Option<String>,
10    pub download_file: String,
11}
12
13#[derive(Debug, Default, Deserialize)]
14#[serde(default, rename_all = "kebab-case")]
15pub struct DetectSchema {
16    pub version_files: Option<Vec<String>>,
17}
18
19#[derive(Debug, Default, Deserialize)]
20#[serde(default, rename_all = "kebab-case")]
21pub struct InstallSchema {
22    pub arch: HashMap<String, String>,
23    pub checksum_url: Option<String>,
24    pub checksum_url_canary: Option<String>,
25    pub download_url: String,
26    pub download_url_canary: Option<String>,
27}
28
29#[derive(Debug, Default, Deserialize)]
30#[serde(default, rename_all = "kebab-case")]
31pub struct GlobalsSchema {
32    pub install_args: Option<Vec<String>>,
33    pub lookup_dirs: Vec<String>,
34    pub package_prefix: Option<String>,
35    pub uninstall_args: Option<Vec<String>>,
36}
37
38#[derive(Debug, Deserialize)]
39#[serde(default, rename_all = "kebab-case")]
40pub struct ResolveSchema {
41    // Manifest
42    pub manifest_url: Option<String>,
43    pub manifest_version_key: String,
44    // Tags
45    pub git_url: Option<String>,
46    pub git_tag_pattern: String,
47}
48
49impl Default for ResolveSchema {
50    fn default() -> Self {
51        ResolveSchema {
52            manifest_url: None,
53            manifest_version_key: "version".to_string(),
54            git_url: None,
55            git_tag_pattern: r"^v?((\d+)\.(\d+)\.(\d+))".to_string(),
56        }
57    }
58}
59
60#[derive(Debug, Deserialize)]
61#[serde(default, rename_all = "kebab-case")]
62pub struct ShimSchema {
63    pub local: bool,
64    pub global: bool,
65    pub parent_bin: Option<String>,
66}
67
68impl Default for ShimSchema {
69    fn default() -> Self {
70        ShimSchema {
71            local: false,
72            global: true,
73            parent_bin: None,
74        }
75    }
76}
77
78#[derive(Debug, Default, Deserialize)]
79#[serde(rename_all = "kebab-case")]
80pub enum SchemaType {
81    #[default]
82    Language,
83    DependencyManager,
84    Cli,
85}
86
87#[derive(Debug, Default, Deserialize)]
88#[serde(default, rename_all = "kebab-case")]
89pub struct Schema {
90    pub name: String,
91    #[serde(rename = "type")]
92    pub type_of: SchemaType,
93    pub platform: HashMap<String, PlatformMapper>,
94
95    pub detect: DetectSchema,
96    pub install: InstallSchema,
97    pub globals: GlobalsSchema,
98    pub resolve: ResolveSchema,
99    pub shim: ShimSchema,
100}