repokit 5.0.3

A knowledgebase for your repository - wrapped in a CLI
use std::collections::HashMap;

#[derive(Clone)]
pub struct InternalExecutableDefinition {
    pub name: String,
    pub description: String,
    pub args: Option<HashMap<String, String>>,
}

pub struct InternalExecutableDefinitionInput<'a, const N: usize> {
    pub name: &'a str,
    pub description: &'a str,
    pub args: [(&'a str, &'a str); N],
}

impl InternalExecutableDefinition {
    pub fn define<const N: usize>(
        definition: InternalExecutableDefinitionInput<N>,
    ) -> InternalExecutableDefinition {
        let InternalExecutableDefinitionInput {
            name,
            description,
            args,
        } = definition;
        InternalExecutableDefinition {
            name: String::from(name),
            description: String::from(description),
            args: InternalExecutableDefinition::args(args),
        }
    }

    pub fn args<const N: usize>(tuples: [(&str, &str); N]) -> Option<HashMap<String, String>> {
        if tuples.is_empty() {
            return None;
        }
        Some(HashMap::from(tuples.map(|(key, value)| {
            (String::from(key), String::from(value))
        })))
    }
}