tftio_cli_common/
types.rs1#[derive(Debug, Clone)]
7pub struct RepoInfo {
8 pub owner: &'static str,
10 pub name: &'static str,
12}
13
14impl RepoInfo {
15 #[must_use]
17 pub const fn new(owner: &'static str, name: &'static str) -> Self {
18 Self { owner, name }
19 }
20}
21
22#[derive(Debug, Clone)]
24pub struct DoctorCheck {
25 pub name: String,
27 pub passed: bool,
29 pub message: Option<String>,
31}
32
33impl DoctorCheck {
34 #[must_use]
36 pub fn pass(name: impl Into<String>) -> Self {
37 Self {
38 name: name.into(),
39 passed: true,
40 message: None,
41 }
42 }
43
44 #[must_use]
46 pub fn fail(name: impl Into<String>, message: impl Into<String>) -> Self {
47 Self {
48 name: name.into(),
49 passed: false,
50 message: Some(message.into()),
51 }
52 }
53
54 pub fn file_exists(path: impl AsRef<std::path::Path>) -> Self {
59 let path_ref = path.as_ref();
60 if path_ref.exists() && path_ref.is_file() {
61 Self::pass(format!("File exists: {}", path_ref.display()))
62 } else {
63 Self::fail(
64 format!("File check: {}", path_ref.display()),
65 format!("File not found: {}", path_ref.display()),
66 )
67 }
68 }
69
70 pub fn dir_exists(path: impl AsRef<std::path::Path>) -> Self {
75 let path_ref = path.as_ref();
76 if path_ref.exists() && path_ref.is_dir() {
77 Self::pass(format!("Directory exists: {}", path_ref.display()))
78 } else {
79 Self::fail(
80 format!("Directory check: {}", path_ref.display()),
81 format!("Directory not found: {}", path_ref.display()),
82 )
83 }
84 }
85}
86
87#[cfg(test)]
88mod tests {
89 use super::*;
90
91 #[test]
92 fn test_repo_info_creation() {
93 let repo = RepoInfo::new("workhelix", "prompter");
94 assert_eq!(repo.owner, "workhelix");
95 assert_eq!(repo.name, "prompter");
96 }
97
98 #[test]
99 fn test_doctor_check_pass() {
100 let check = DoctorCheck::pass("test check");
101 assert!(check.passed);
102 assert_eq!(check.name, "test check");
103 assert!(check.message.is_none());
104 }
105
106 #[test]
107 fn test_doctor_check_fail() {
108 let check = DoctorCheck::fail("test check", "error message");
109 assert!(!check.passed);
110 assert_eq!(check.name, "test check");
111 assert_eq!(check.message, Some("error message".to_string()));
112 }
113}