warlocks_cauldron/providers/
path.rs1use super::dependencies::*;
2
3
4pub enum PlatformType { Win, Linux }
6
7impl PlatformType {
8 pub fn detect() -> Self {
10 match cfg!(windows) {
11 true => Self::Win,
12 false => Self::Linux,
13 }
14 }
15}
16
17pub struct Path {
19 is_win: bool
20}
21
22impl Path {
23 pub fn new(platform: PlatformType) -> Self {
25 Self {
26 is_win: match platform {
27 PlatformType::Win => true,
28 _ => false,
29 }
30 }
31 }
32
33 fn path_gen<const N: usize>(&self, paths: [&str; N]) -> String {
35 paths.iter().join(&self.delimetr())
36 }
37
38 pub fn delimetr(&self) -> String {
40 match self.is_win {
41 true => "\\",
42 false => "/",
43 }.to_string()
44 }
45
46 pub fn root(&self) -> String {
48 match self.is_win {
49 true => "C:\\Windows",
50 false => "/",
51 }.to_string()
52 }
53
54 pub fn home(&self) -> String {
56 match self.is_win {
57 true => "C:\\Users",
58 false => "/home",
59 }.to_string()
60 }
61
62 pub fn user(&self) -> String {
64 let user = get_random_element(USERNAMES.iter());
65 match self.is_win {
66 true => user[..1].to_uppercase() + &user[1..],
67 false => user.to_string(),
68 }
69 }
70
71 pub fn users_folder(&self) -> String {
73 let folder = get_random_element(FOLDERS.iter());
74 self.path_gen([&self.home(), &self.user(), &folder])
75 }
76
77 pub fn dev_dir(&self) -> String {
79 let folder = get_random_element(vec!["Development", "Dev"].into_iter());
80 let stack = get_random_element(PROGRAMMING_LANGS.iter());
81 self.path_gen([&self.home(), &self.user(), folder, stack])
82 }
83
84 pub fn project_dir(&self) -> String {
86 let project = get_random_element(PROJECT_NAMES.iter());
87 self.path_gen([&self.dev_dir(), project])
88 }
89}