|
|
@ -16,11 +16,20 @@ pub fn read_cfg(verbose: bool) -> Config {
|
|
|
|
|
|
|
|
|
|
|
|
// Reading the config file to an UnexpandedConfig struct
|
|
|
|
// Reading the config file to an UnexpandedConfig struct
|
|
|
|
let file = fs::read_to_string("mlc.toml").unwrap();
|
|
|
|
let file = fs::read_to_string("mlc.toml").unwrap();
|
|
|
|
let config: UnexpandedConfig = toml::from_str(&file).unwrap();
|
|
|
|
let config: UnexpandedConfig = toml::from_str(&file).unwrap_or_else(|e| {
|
|
|
|
|
|
|
|
crash!(
|
|
|
|
|
|
|
|
AppExitCode::ConfigParseError,
|
|
|
|
|
|
|
|
"Error parsing config file: {}",
|
|
|
|
|
|
|
|
e
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
// This is unreachable, but rustc complains about it otherwise
|
|
|
|
|
|
|
|
std::process::exit(1);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
log!(verbose, "Config file read: {:?}", config);
|
|
|
|
log!(verbose, "Config file read: {:?}", config);
|
|
|
|
|
|
|
|
|
|
|
|
// Crash if incorrect mode is set
|
|
|
|
// Crash if incorrect mode is set
|
|
|
|
if config.mode != "workspace" && config.mode != "repository" {
|
|
|
|
if config.base.mode != "workspace" && config.base.mode != "repository" {
|
|
|
|
crash!(
|
|
|
|
crash!(
|
|
|
|
AppExitCode::InvalidMode,
|
|
|
|
AppExitCode::InvalidMode,
|
|
|
|
"Invalid mode in mlc.toml, must be either \"repository\" or \"workspace\""
|
|
|
|
"Invalid mode in mlc.toml, must be either \"repository\" or \"workspace\""
|
|
|
@ -30,7 +39,7 @@ pub fn read_cfg(verbose: bool) -> Config {
|
|
|
|
let mut expanded_repos: Vec<Repo> = vec![];
|
|
|
|
let mut expanded_repos: Vec<Repo> = vec![];
|
|
|
|
|
|
|
|
|
|
|
|
// Parsing repos from the config file
|
|
|
|
// Parsing repos from the config file
|
|
|
|
for x in config.repo {
|
|
|
|
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();
|
|
|
@ -43,7 +52,7 @@ pub fn read_cfg(verbose: bool) -> Config {
|
|
|
|
// 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 index = split_struct.indx;
|
|
|
|
let name = split_struct.name.replace('!', "");
|
|
|
|
let name = split_struct.name.replace('!', "");
|
|
|
|
let url = config.urls[index - 1].replace("%repo%", &name);
|
|
|
|
let url = config.repositories.urls[index - 1].replace("%repo%", &name);
|
|
|
|
let priority = &split_struct.name.matches('!').count();
|
|
|
|
let priority = &split_struct.name.matches('!').count();
|
|
|
|
|
|
|
|
|
|
|
|
// Creates and pushes Repo struct to expanded_repos
|
|
|
|
// Creates and pushes Repo struct to expanded_repos
|
|
|
@ -58,10 +67,11 @@ pub fn read_cfg(verbose: bool) -> Config {
|
|
|
|
|
|
|
|
|
|
|
|
// Returns parsed config file
|
|
|
|
// Returns parsed config file
|
|
|
|
let conf = Config {
|
|
|
|
let conf = Config {
|
|
|
|
mode: config.mode,
|
|
|
|
mode: config.base.mode,
|
|
|
|
sign: config.sign,
|
|
|
|
smart_pull: config.base.smart_pull,
|
|
|
|
name: config.name,
|
|
|
|
sign: config.mode.repository.sign,
|
|
|
|
smart_pull: config.smart_pull,
|
|
|
|
name: config.mode.repository.name,
|
|
|
|
|
|
|
|
build_on_update: config.mode.repository.build_on_update,
|
|
|
|
repo: expanded_repos,
|
|
|
|
repo: expanded_repos,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
log!(verbose, "Config: {:?}", conf);
|
|
|
|
log!(verbose, "Config: {:?}", conf);
|
|
|
|