mirror of
https://github.com/sergi0g/cup.git
synced 2025-11-17 09:33:38 -05:00
Add requirement for version key to new config
This commit is contained in:
@@ -5,6 +5,11 @@
|
|||||||
"description": "A schema for Cup's config file",
|
"description": "A schema for Cup's config file",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"version": {
|
||||||
|
"type": "integer",
|
||||||
|
"minimum": 3,
|
||||||
|
"maximum": 3
|
||||||
|
},
|
||||||
"registries": {
|
"registries": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"description": "Configuration options for specific registries",
|
"description": "Configuration options for specific registries",
|
||||||
@@ -57,5 +62,6 @@
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"minLength": 1
|
"minLength": 1
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"required": ["version"]
|
||||||
}
|
}
|
||||||
@@ -32,12 +32,13 @@ pub struct RegistryConfig {
|
|||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct ImageConfig {
|
pub struct ImageConfig {
|
||||||
pub extra: Vec<String>,
|
pub extra: Vec<String>,
|
||||||
pub exclude: Vec<String>
|
pub exclude: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Deserialize)]
|
#[derive(Clone, Deserialize)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
|
version: u8,
|
||||||
pub registries: FxHashMap<String, RegistryConfig>,
|
pub registries: FxHashMap<String, RegistryConfig>,
|
||||||
pub images: ImageConfig,
|
pub images: ImageConfig,
|
||||||
pub theme: Theme,
|
pub theme: Theme,
|
||||||
@@ -49,6 +50,7 @@ pub struct Config {
|
|||||||
impl Config {
|
impl Config {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
version: 3,
|
||||||
registries: FxHashMap::default(),
|
registries: FxHashMap::default(),
|
||||||
images: ImageConfig::default(),
|
images: ImageConfig::default(),
|
||||||
theme: Theme::Default,
|
theme: Theme::Default,
|
||||||
@@ -73,10 +75,14 @@ impl Config {
|
|||||||
}
|
}
|
||||||
/// Parses and validates the config.
|
/// Parses and validates the config.
|
||||||
pub fn parse(&self, raw_config: &str) -> Self {
|
pub fn parse(&self, raw_config: &str) -> Self {
|
||||||
match serde_json::from_str(raw_config) {
|
let config: Self = match serde_json::from_str(raw_config) {
|
||||||
Ok(config) => config,
|
Ok(config) => config,
|
||||||
Err(e) => error!("Unexpected error occured while parsing config: {}", e),
|
Err(e) => error!("Unexpected error occured while parsing config: {}", e),
|
||||||
|
};
|
||||||
|
if config.version != 2 {
|
||||||
|
error!("You are trying to run Cup with an incompatible config file! Please migrate your config file to the version 3, or if you have already done so, add a `version` key with the value `3`.")
|
||||||
}
|
}
|
||||||
|
config
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user