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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//This file is part of tmplgen
//
//tmplgen is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//tmplgen is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with tmplgen.  If not, see <http://www.gnu.org/licenses/>.

use serde_derive::Deserialize;
use std::io::Read;

/// The TemplateBuilder struct, which is used to build a [Template](crate::types::Template)
pub struct TmplBuilder {
    pub pkg_name: String,
    pub pkg_type: Option<PkgType>,
    pub pkg_info: Option<PkgInfo>,
    pub deps: Option<Vec<String>>,
}

pub struct Template {
    pub inner: String,
    pub name: String,
}

impl Read for Template {
    fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
        self.inner.as_bytes().read(buf)
    }
}

/// The PkgType enum, containing all types of packages tmplgen can handle
#[derive(Copy, Clone, Eq, Ord, PartialOrd, Hash, Debug, PartialEq)]
pub enum PkgType {
    Crate,
    Gem,
    PerlDist,
}

/// The Dependencies struct that contains all dependencies a package might have
#[derive(Clone, Eq, Ord, PartialOrd, Hash, Default, Debug, PartialEq)]
pub struct Dependencies {
    pub host: Option<Vec<String>>,
    pub make: Option<Vec<String>>,
    pub run: Option<Vec<String>>,
}

/// The PkgInfo struct, that contains all info relevant to the package
#[derive(Clone, Eq, Ord, PartialOrd, Hash, Default, Debug, PartialEq)]
pub struct PkgInfo {
    pub pkg_name: String,
    pub version: String,
    pub description: String,
    pub homepage: String,
    pub license: Vec<String>,
    pub dependencies: Option<Dependencies>,
    pub sha: String,
    pub download_url: Option<String>,
}

#[derive(Debug, Deserialize)]
pub(crate) struct BuiltIns {
    pub perl: Vec<BuiltInDep>,
    pub ruby: Vec<BuiltInDep>,
}

#[derive(Debug, Deserialize)]
pub(crate) struct BuiltInDep {
    pub name: String,
}

#[derive(Debug, Deserialize)]
pub(crate) struct CorrectedVals {
    pub licenses: Vec<CorrectedLicenses>,
}

#[derive(Debug, Deserialize)]
pub(crate) struct CorrectedLicenses {
    pub is: String,
    pub should: String,
}