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
/// # Config Reference
///
/// Config file reference for `a_cli_tool`.
///
/// By default `a_cli_tool` looks for configuration in `./config.yaml`,
/// unless another path is specified with the `-c/--config` parameter.
///
/// `Config` details the structure of the configuration.
///
/// NOTE: Field names will appear in YAML as they appear here, unless
/// otherwise specified in the accompanying description.
///
#[derive(serde::Deserialize)]
pub struct Config {
    /// The name of the thing this CLI tool is building for you.
    ///
    name: String,

    /// The version of the thing this CLI tool will build for you.
    ///
    /// This is a [SemVer][semver] version, e.g:
    ///
    /// ```yaml
    /// version: 1.2.3
    /// ```
    ///
    /// [semver]: https://semver.org/
    ///
    version: semver::Version,

    /// A description of the thing this CLI tool is building for you.
    ///
    description: String,

    /// The configuration for the source of data for this tool.
    ///
    source: Source,

    /// A path to write the created thing to.
    ///
    target: std::path::PathBuf,
}

/// The configuration for the source of data for this tool.
///
/// This can either be set to a local file:
///
/// ```yaml
/// source:
///   file: path/to/file.yaml
/// ```
///
/// Or a URL:
///
/// ```yaml
/// source:
///   url: https://urlofsource.com/sourcedata/
/// ```
///
/// ---
///
/// Back to:
///
/// - [Configuration Reference](./struct.Config.html#structfield.source)
///
#[derive(serde::Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Source {
    /// ```yaml
    /// file: <path to file>
    /// ```
    ///
    File(std::path::PathBuf),

    /// ```yaml
    /// url: <url>
    /// ```
    ///
    Url(String),
}