punktf_lib/profile/dotfile.rs
1//! Defines definitions for a [`Dotfile`] which is the basic building block
2//! to define required/deployable items in a [`Profile`](`crate::profile::Profile`).
3
4use serde::{Deserialize, Serialize};
5
6use crate::profile::{transform::ContentTransformer, variables::Variables, MergeMode, Priority};
7
8use std::path::PathBuf;
9
10/// A dotfile represents a single item to be deployed by `punktf`. This can
11/// either be a single file or a directory. This struct holds attributes to
12/// control how the item will be deployed.
13#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
14#[serde(deny_unknown_fields)]
15pub struct Dotfile {
16 /// Relative path inside the
17 /// [`PunktfSource::dotfiles`](`crate::profile::source::PunktfSource::dotfiles`)
18 /// directory.
19 pub path: PathBuf,
20
21 /// Alternative relative name/path for the dotfile. This name will be used
22 /// instead of [`Dotfile::path`](`crate::profile::dotfile::Dotfile::path`)
23 /// when deploying. If this is set and the
24 /// dotfile is a directory, it will be deployed under the given name and
25 /// not in the
26 /// [`PunktfSource::root`](`crate::profile::source::PunktfSource::root`)
27 /// directory.
28 #[serde(skip_serializing_if = "Option::is_none", default)]
29 pub rename: Option<PathBuf>,
30
31 /// Alternative absolute deploy target path. This will be used instead of
32 /// [`Profile::target`](`crate::profile::Profile::target`) when deploying.
33 #[serde(alias = "target", skip_serializing_if = "Option::is_none", default)]
34 pub overwrite_target: Option<PathBuf>,
35
36 /// Priority of the dotfile. Dotfiles with higher priority as others are
37 /// allowed to overwrite an already deployed dotfile if the
38 /// [Dotfile::merge](`crate::profile::dotfile::Dotfile::merge`) allows for it.
39 #[serde(skip_serializing_if = "Option::is_none", default)]
40 pub priority: Option<Priority>,
41
42 /// Variables specifically defined for this dotfile. These variables will
43 /// take precedence over the ones defined in
44 /// [`Profile::variables`](`crate::profile::Profile::variables`).
45 #[serde(skip_serializing_if = "Option::is_none", default)]
46 pub variables: Option<Variables>,
47
48 /// Content transform defined for the dotfile. These variables will take
49 /// precedence over the ones defined in
50 /// [`profile::Profile::transformers`](`crate::profile::Profile::transformers`).
51 #[serde(skip_serializing_if = "Vec::is_empty", default)]
52 pub transformers: Vec<ContentTransformer>,
53
54 /// Merge operation for already existing dotfiles with the same or higher
55 /// priority.
56 #[serde(skip_serializing_if = "Option::is_none", default)]
57 pub merge: Option<MergeMode>,
58
59 /// Indicates if the dotfile should be treated as a template. If this is `false`
60 /// no template processing will be done.
61 #[serde(skip_serializing_if = "Option::is_none", default)]
62 pub template: Option<bool>,
63}
64
65impl Dotfile {
66 /// Checks if the dotfile is considered to be a template.
67 pub fn is_template(&self) -> bool {
68 self.template.unwrap_or(true)
69 }
70}