Skip to main content

vs_config/
types.rs

1//! Shared configuration data types used across the workspace.
2
3use std::collections::BTreeMap;
4use std::path::PathBuf;
5
6use serde::{Deserialize, Serialize};
7
8/// Resolution scope for a tool version.
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub enum Scope {
11    /// Version pinned in a project file.
12    Project,
13    /// Version pinned for the active shell session.
14    Session,
15    /// Version pinned globally for the user.
16    Global,
17    /// Version provided by the operating system.
18    System,
19}
20
21/// Source metadata for a resolved tool version.
22#[derive(Debug, Clone, PartialEq, Eq)]
23pub struct ResolvedToolVersion {
24    /// Tool name.
25    pub plugin: String,
26    /// Resolved version string.
27    pub version: String,
28    /// Scope that produced the version.
29    pub scope: Scope,
30    /// Source file backing the version.
31    pub source: PathBuf,
32}
33
34/// The active home directory plus migration candidates.
35#[derive(Debug, Clone, PartialEq, Eq)]
36pub struct HomeLayout {
37    /// Active home used by `vs`.
38    pub active_home: PathBuf,
39    /// Legacy home locations that may be migrated.
40    pub migration_candidates: Vec<PathBuf>,
41}
42
43/// Global configuration file for `vs`.
44#[derive(Debug, Clone, Serialize, Deserialize, Default)]
45#[serde(default, rename_all = "camelCase")]
46pub struct AppConfig {
47    /// Proxy configuration.
48    pub proxy: ProxyConfig,
49    /// SDK storage configuration.
50    pub storage: StorageConfig,
51    /// Registry configuration.
52    pub registry: RegistryConfig,
53    /// Legacy version file settings.
54    pub legacy_version_file: LegacyVersionFileConfig,
55    /// Cache settings.
56    pub cache: CacheConfig,
57}
58
59/// Proxy configuration written to `config.yaml`.
60#[derive(Debug, Clone, Serialize, Deserialize, Default)]
61#[serde(default, rename_all = "camelCase")]
62pub struct ProxyConfig {
63    /// Whether the proxy is enabled.
64    pub enable: bool,
65    /// Proxy URL.
66    pub url: String,
67}
68
69/// Storage configuration written to `config.yaml`.
70#[derive(Debug, Clone, Serialize, Deserialize, Default)]
71#[serde(default, rename_all = "camelCase")]
72pub struct StorageConfig {
73    /// Alternative SDK storage root.
74    pub sdk_path: String,
75}
76
77/// Registry configuration written to `config.yaml`.
78#[derive(Debug, Clone, Serialize, Deserialize, Default)]
79#[serde(default, rename_all = "camelCase")]
80pub struct RegistryConfig {
81    /// Registry base address or index URL.
82    pub address: String,
83}
84
85/// Legacy version file configuration written to `config.yaml`.
86#[derive(Debug, Clone, Serialize, Deserialize)]
87#[serde(default, rename_all = "camelCase")]
88pub struct LegacyVersionFileConfig {
89    /// Whether legacy file parsing is enabled.
90    pub enable: bool,
91    /// Legacy parsing strategy.
92    pub strategy: String,
93}
94
95impl Default for LegacyVersionFileConfig {
96    fn default() -> Self {
97        Self {
98            enable: true,
99            strategy: String::from("specified"),
100        }
101    }
102}
103
104/// Cache configuration written to `config.yaml`.
105#[derive(Debug, Clone, Serialize, Deserialize)]
106#[serde(default, rename_all = "camelCase")]
107pub struct CacheConfig {
108    /// Available hook cache duration string.
109    pub available_hook_duration: String,
110}
111
112impl Default for CacheConfig {
113    fn default() -> Self {
114        Self {
115            available_hook_duration: String::from("12h"),
116        }
117    }
118}
119
120/// Tool versions written in TOML configuration files.
121#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
122pub struct ToolVersions {
123    /// Tools pinned in the file.
124    #[serde(default)]
125    pub tools: BTreeMap<String, String>,
126}