mapm-cli 6.1.0

The command-line implementation of mapm
use crate::utils::msg;

use mapm::problem::Views::*;
use mapm::problem::{fetch_problem, Problem, Views};
use mapm::result::MapmErr::*;

use std::path::Path;

use colour::*;

// Because of clap, we won't have both hide and show be both

pub fn parse_views(hide: Option<Vec<String>>, show: Option<Vec<String>>) -> Views {
    match hide {
        Some(views) => Hide(views),
        None => match show {
            Some(views) => Show(views),
            None => Hide(vec![]),
        },
    }
}

pub fn problem_names_to_problems(
    problem_dir: &Path,
    problem_names: &Vec<String>,
    views: Views,
) -> Vec<Problem> {
    let mut problems: Vec<Problem> = Vec::new();
    for problem_name in problem_names {
        let problem_result = fetch_problem(problem_name, problem_dir);
        match problem_result {
            Ok(mut problem) => {
                problems.push(problem.filter_keys(&views));
            }
            Err(err) => match err {
                ProblemErr(msg) => {
                    e_yellow_ln!("{}", msg);
                }
                _ => {
                    e_magenta_ln!("{}", msg::VIEW_NOT_PROBLEMERR);
                    quit::with_code(exitcode::SOFTWARE);
                }
            },
        }
    }
    problems
}