use super::errors::*;
use std::fs::{read_dir, read_to_string};
pub fn load_definitions() -> Result<String> {
let mut files = vec![];
let paths = read_dir(".").expect("Failed to access current directory");
for entry in paths.flatten() {
let file_type = entry.file_type().expect("Failed to get file type");
if file_type.is_file() {
let file_name = entry.file_name().to_string_lossy().to_string();
if file_name.ends_with(".taskcmd") {
files.push(file_name);
}
}
}
files.sort();
files.reverse();
if let Some(file_name) = files.first() {
Ok(read_to_string(file_name).expect("Failed to read task definitions file"))
} else {
Err(err_definitions_not_found())
}
}