agpm_project/
lib.rs

1#![warn(missing_docs)]
2#![doc = include_str!("../README.md")]
3
4use amisgitpm::ProjectIface;
5#[cfg(feature = "serde")]
6use serde::{Deserialize, Serialize};
7
8/// What to do when updating a project
9#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10#[derive(Debug, Clone, Copy, Default)]
11pub enum UpdatePolicy {
12    /// Update the project to the newest version every time
13    Always,
14    /// Ask whether to update or not
15    Ask,
16    /// Do not update the repo, **default** value
17    #[default]
18    Never,
19}
20
21impl std::fmt::Display for UpdatePolicy {
22    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23        match self {
24            Self::Always => {
25                write!(f, "Always try to update the project")
26            }
27            Self::Ask => {
28                write!(f, "Ask wether ot update or not")
29            }
30            Self::Never => {
31                write!(f, "Never try to update the project")
32            }
33        }
34    }
35}
36
37/// `agpm`'s Project structure. It has one extra field. The `update_policy` stores
38/// information that determines behavior when interactively trying to update.
39#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
40#[derive(Debug, Clone, Default)]
41pub struct Project {
42    /// The name of the projects
43    pub name: String,
44    /// The name of the directory in which the project is going to be stored
45    pub dir: String,
46    /// The url from which to git clone the project, it can be a file url
47    pub url: String,
48    /// A string to identify the branch which you want installed
49    pub ref_string: String,
50    /// Whether to update, ask or never update the project
51    pub update_policy: UpdatePolicy,
52    /// How to install the project. The elements are joined with && before execution
53    pub install_script: Vec<String>,
54    /// How to uninstall the project. The elements are joined with && before execution
55    pub uninstall_script: Vec<String>,
56}
57
58impl ProjectIface for Project {
59    fn get_name(&self) -> &str {
60        &self.name
61    }
62    fn get_dir(&self) -> &str {
63        &self.dir
64    }
65    fn get_url(&self) -> &str {
66        &self.url
67    }
68    fn get_ref_string(&self) -> &str {
69        &self.ref_string
70    }
71    fn get_install(&self) -> &[String] {
72        &self.install_script
73    }
74    fn get_uninstall(&self) -> &[String] {
75        &self.uninstall_script
76    }
77}