|
|
|
@ -16,11 +16,20 @@ pub fn read_cfg(verbose: bool) -> Config {
|
|
|
|
|
|
|
|
|
|
// Reading the config file to an UnexpandedConfig struct
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
// Crash if incorrect mode is set
|
|
|
|
|
if config.mode != "workspace" && config.mode != "repository" {
|
|
|
|
|
if config.base.mode != "workspace" && config.base.mode != "repository" {
|
|
|
|
|
crash!(
|
|
|
|
|
AppExitCode::InvalidMode,
|
|
|
|
|
"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![];
|
|
|
|
|
|
|
|
|
|
// Parsing repos from the config file
|
|
|
|
|
for x in config.repo {
|
|
|
|
|
for x in config.repositories.name {
|
|
|
|
|
log!(verbose, "Parsing repo: {:?}", x);
|
|
|
|
|
// Splits the repo name and index inta a SplitRepo struct
|
|
|
|
|
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
|
|
|
|
|
let index = split_struct.indx;
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
// Creates and pushes Repo struct to expanded_repos
|
|
|
|
@ -58,10 +67,11 @@ pub fn read_cfg(verbose: bool) -> Config {
|
|
|
|
|
|
|
|
|
|
// Returns parsed config file
|
|
|
|
|
let conf = Config {
|
|
|
|
|
mode: config.mode,
|
|
|
|
|
sign: config.sign,
|
|
|
|
|
name: config.name,
|
|
|
|
|
smart_pull: config.smart_pull,
|
|
|
|
|
mode: config.base.mode,
|
|
|
|
|
smart_pull: config.base.smart_pull,
|
|
|
|
|
sign: config.mode.repository.sign,
|
|
|
|
|
name: config.mode.repository.name,
|
|
|
|
|
build_on_update: config.mode.repository.build_on_update,
|
|
|
|
|
repo: expanded_repos,
|
|
|
|
|
};
|
|
|
|
|
log!(verbose, "Config: {:?}", conf);
|
|
|
|
|