fn execute()

in guard/src/commands/test.rs [52:103]


    fn execute(&self, app: &ArgMatches<'_>) -> Result<i32> {
        let mut exit_code = 0;
        let file = app.value_of("rules-file").unwrap();
        let data = app.value_of("test-data").unwrap();
        let cmp = if let Some(_ignored) = app.value_of(ALPHABETICAL.0) {
            alpabetical
        } else if let Some(_ignored) = app.value_of(LAST_MODIFIED.0) {
            last_modified
        } else {
            regular_ordering
        };
        let verbose = if app.is_present("verbose") { true } else { false };

        let data_test_files = get_files_with_filter(&data, cmp, |entry| {
            entry.file_name().to_str()
                .map(|name|
                    name.ends_with(".json") ||
                    name.ends_with(".yaml") ||
                    name.ends_with(".JSON") ||
                    name.ends_with(".YAML") ||
                    name.ends_with(".yml")  ||
                    name.ends_with(".jsn")
                ).unwrap_or(false)
        })?;

        let path = PathBuf::try_from(file)?;
        let rule_file = File::open(path.clone())?;
        if !rule_file.metadata()?.is_file() {
            return Err(Error::new(ErrorKind::IoError(
                std::io::Error::from(std::io::ErrorKind::InvalidInput)
            )))
        }

        let ruleset = vec![path];
        for rules in iterate_over(&ruleset, |content, file| {
            Ok((content, file.to_str().unwrap_or("").to_string()))
        }) {
            match rules {
                Err(e) => println!("Unable to read rule file content {}", e),
                Ok((context, path)) => {
                    let span = crate::rules::parser::Span::new_extra(&context, &path);
                    match crate::rules::parser::rules_file(span) {
                        Err(e) => println!("Parse Error on ruleset file {}", e),
                        Ok(rules) => {
                            exit_code = test_with_data(&data_test_files, &rules, verbose)?;
                        }
                    }
                }
            }
        }
        Ok(exit_code)
    }