Newer
Older
use yaml_rust::{YamlLoader, YamlEmitter, ScanError, Yaml};
use std::error::Error;
use std::path::Path;
use std::collections::HashMap;
use std::process::{Command, Stdio};
use tera::{Context, Tera};
pub fn check_syntax(path: &Path) -> Result<bool, Box<dyn Error + '_>> {
let filename = Path::new(path).file_name().unwrap().to_str().unwrap();
// Reading the file as a string
let conf_file = match fs::read_to_string(path) {
Ok(file) => file,
Err(err) => return Err(Box::new(err)),
};
// Loading previously read string with yamlloader to check the syntax
match YamlLoader::load_from_str(&conf_file) {
Ok(content) => {
let conf = content[0].as_hash().unwrap(); // Getting config
let mut line = 2;
// Checking if the binary path has been given
if !conf.contains_key(&Yaml::String(String::from("bin"))) {
return Err(Box::new(JobConfError::new(JobConfErrorType::MissingPathField, 0, filename)))
}else {
// Checking if list of parameters exist within the file
if !conf.contains_key(&Yaml::String(String::from("parameters"))) {
return Err(Box::new(JobConfError::new(JobConfErrorType::MissingParametersList, 1, filename)))
}else {
// Checking if the parameters list isn't empy
let params = conf[&Yaml::String(String::from("parameters"))].as_vec().unwrap();
return Err(Box::new(JobConfError::new(JobConfErrorType::MissingParametersList, 2, filename)))
}else {
// Checking the syntax of each given parameter
for entry in params {
let param = match entry.as_hash() {
Some(p) => p,
None => return Err(Box::new(JobConfError::new(JobConfErrorType::MissingParametersList, line, filename))),
};
let value_type = String::from("string");
let named: bool = false;
// Checking the parameter name
if param.contains_key(&Yaml::String(String::from("name"))){
}else {
}
if param.contains_key(&Yaml::String(String::from("value-type"))){
}else {
}
if param.contains_key(&Yaml::String(String::from("default-value"))){
let value = param.get(&Yaml::String(String::from("default-value")));
if check_type() == true {
}
line += 1;
}
if param.contains_key(&Yaml::String(String::from("commnet"))){
line += 1;
}
if param.contains_key(&Yaml::String(String::from("required"))){
line += 1;
}else {
}
if param.contains_key(&Yaml::String(String::from("named"))){
line += 1;
}else {
}
if named {
}
}
}
},
Err(err) => return Err(Box::new(err)),
}
}
fn generate_command() {
}
pub fn generate_sbatch() {
}
#[cfg(test)]
mod tests {
use super::check_type;
use super::check_syntax;
use super::generate_command;
use super::generate_sbatch;