debate-derive 1.0.0

derive macro for the `debate` CLI arguments parser
Documentation
pub mod flag_set;
pub mod subcommand;

use std::borrow::Cow;

use darling::{FromAttributes, util::SpannedValue};
use proc_macro2::Span;
use quote::format_ident;
use syn::Ident;

use super::IdentString;

#[derive(FromAttributes)]
#[darling(attributes(debate))]
pub struct ValueEnumAttr {
    pub subcommand: Option<()>,
    pub short: Option<SpannedValue<()>>,
    pub long: Option<SpannedValue<()>>,
    // TODO: help
    // TODO: name attribute to rename the command
}

pub fn create_non_colliding_ident<'a>(
    root: &str,
    variants: impl Iterator<Item = &'a IdentString<'a>> + Clone,
) -> Ident {
    let mut ident = Cow::Borrowed(root);

    while variants.clone().any(|existing| existing.as_str() == ident) {
        ident = Cow::Owned(format!("_{ident}"));
    }

    format_ident!("{ident}", span = Span::mixed_site())
}