aboutsummaryrefslogtreecommitdiff
path: root/derive-macro/src/item.rs
blob: 5d3f4cdb10124b8c3f739918e19acc4f26669b6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use syn::{self, ext::IdentExt, spanned::Spanned, Attribute, Field, Ident, LitStr, Type, Variant};

#[derive(Clone)]
pub struct Item {
    ident: Ident,
    ty: Option<Type>,
    doc_comment: Vec<Method>,
    value_parser: Option<ValueParser>,
}

impl Item {
    pub fn from_key_field(field: &Field) -> Self {
        let ident = field.ident.clone().unwrap();
        let span = field.span();
        let ty = Ty::from_syn_ty(&field.ty);
        let kind = Sp::new(Kind::Arg(ty), span);
        let mut res = Self::new(Name::Derived(name), ident, Some(field.ty.clone()), kind);
        let parsed_attrs = ClapAttr::parse_all(&field.attrs);
        res.push_attrs(&parsed_attrs);
        if matches!(&*res.kind, Kind::Arg(_)) {
            res.push_doc_comment(&field.attrs, "help", Some("long_help"));
        }

        res
    }
}