New format oop

main
Michal 2 years ago
parent 98a4bf55cf
commit 2f70e06e85
No known key found for this signature in database
GPG Key ID: A6A1A4DCB22279B9

@ -14,11 +14,11 @@ on_gen = true
[mode.workspace] [mode.workspace]
[repositories] [repositories]
name = [ repos = [
"1::crystal-keyring", "crs:malachite/development",
"2::pfetch!", "pkg:pfetch!",
] ]
urls = [
"https://github.com/crystal-linux/%repo%", [repositories.urls]
"https://github.com/crystal-linux/pkgbuild.%repo%", crs = "https://github.com/crystal-linux/%repo%"
] pkg = "https://github.com/crystal-linux/pkgbuild.%repo%"

@ -1,4 +1,5 @@
use serde_derive::Deserialize; use serde_derive::Deserialize;
use std::collections::HashMap;
//// Config structs //// Config structs
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
@ -47,7 +48,7 @@ pub struct ConfigModeWorkspace {}
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct ConfigRepositories { pub struct ConfigRepositories {
pub name: Vec<String>, pub name: Vec<String>,
pub urls: Vec<String>, pub urls: HashMap<String, String>,
} }
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
@ -66,7 +67,7 @@ pub struct Repo {
#[derive(Debug)] #[derive(Debug)]
pub struct SplitRepo { pub struct SplitRepo {
pub indx: usize, pub id: String,
pub name: String, pub name: String,
} }

@ -42,21 +42,21 @@ pub fn read_cfg(verbose: bool) -> Config {
for x in config.repositories.name { for x in config.repositories.name {
log!(verbose, "Parsing repo: {:?}", x); log!(verbose, "Parsing repo: {:?}", x);
// Splits the repo name and index inta a SplitRepo struct // Splits the repo name and index inta a SplitRepo struct
let split: Vec<&str> = x.split("::").collect(); let split: Vec<&str> = x.split(':').collect();
let split_struct = SplitRepo { let split_struct = SplitRepo {
indx: split[0].parse().unwrap(), id: split[0].parse().unwrap(),
name: split[1].parse().unwrap(), name: split[1].parse().unwrap(),
}; };
log!(verbose, "Split repo: {:?}", split_struct); log!(verbose, "Split repo: {:?}", split_struct);
// Parses all necessary values for expanding the repo to a Repo struct // Parses all necessary values for expanding the repo to a Repo struct
let index = split_struct.indx; let id = split_struct.id;
// If a branch is defined, parse it // If a branch is defined, parse it
let branch = if split_struct.name.contains('@') { let branch = if split_struct.name.contains('/') {
log!(verbose, "Branch defined: {}", split_struct.name); log!(verbose, "Branch defined: {}", split_struct.name);
Some( Some(
split_struct.name.split('@').collect::<Vec<&str>>()[1] split_struct.name.split('/').collect::<Vec<&str>>()[1]
.to_string() .to_string()
.replace('!', ""), .replace('!', ""),
) )
@ -66,14 +66,22 @@ pub fn read_cfg(verbose: bool) -> Config {
}; };
// Strip branch and priority info from the name, if present // Strip branch and priority info from the name, if present
let name = if split_struct.name.contains('@') { let name = if split_struct.name.contains('/') {
split_struct.name.split('@').collect::<Vec<&str>>()[0].to_string() split_struct.name.split('/').collect::<Vec<&str>>()[0].to_string()
} else { } else {
split_struct.name.to_string().replace('!', "") split_struct.name.to_string().replace('!', "")
}; };
// Substitutes the name into the url // Substitutes the name into the url
let url = config.repositories.urls[index - 1].replace("%repo%", &name); let urls = &config.repositories.urls;
let mut urls_vec = vec![];
for (i, url) in urls {
if i == &id {
log!(verbose, "Substituting url: {:?}", url);
urls_vec.push(url);
}
}
let url = urls_vec[0].replace("%repo%", &name);
// Counts instances of ! in the name, and totals a priority accordingly // Counts instances of ! in the name, and totals a priority accordingly
let priority = &split_struct.name.matches('!').count(); let priority = &split_struct.name.matches('!').count();

Loading…
Cancel
Save