• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pkgxdev / pkgx / 13863219990

14 Mar 2025 06:39PM UTC coverage: 91.235%. First build
13863219990

Pull #1151

github

web-flow
Merge e39b8e6c8 into 35f6bbe1d
Pull Request #1151: --query,-Q

35 of 35 new or added lines in 4 files covered. (100.0%)

1374 of 1506 relevant lines covered (91.24%)

18538506.28 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

70.69
/crates/lib/src/config.rs
1
use std::env;
2
use std::io;
3
use std::path::PathBuf;
4

5
#[derive(Debug)]
6
pub struct Config {
7
    pub pantry_dir: PathBuf,
8
    pub pantry_db_file: PathBuf,
9
    pub dist_url: String,
10
    pub pkgx_dir: PathBuf,
11
}
12

13
impl Config {
14
    pub fn new() -> io::Result<Self> {
30✔
15
        let pantry_dir = get_pantry_dir()?;
30✔
16
        let pantry_db_file: PathBuf = get_pantry_db_file()?;
30✔
17
        let dist_url = get_dist_url();
30✔
18
        let pkgx_dir = get_pkgx_dir()?;
30✔
19
        Ok(Self {
30✔
20
            pantry_dir,
30✔
21
            pantry_db_file,
30✔
22
            dist_url,
30✔
23
            pkgx_dir,
30✔
24
        })
30✔
25
    }
30✔
26
}
27

28
fn get_dist_url() -> String {
30✔
29
    if let Ok(env_url) = env::var("PKGX_DIST_URL") {
30✔
30
        return env_url;
×
31
    }
30✔
32
    env!("PKGX_DIST_URL").to_string()
30✔
33
}
30✔
34

35
#[allow(non_snake_case)]
36
fn get_PKGX_PANTRY_DIR() -> Option<PathBuf> {
60✔
37
    if let Ok(env_dir) = env::var("PKGX_PANTRY_DIR") {
60✔
38
        let path = PathBuf::from(env_dir);
×
39
        if path.is_absolute() {
×
40
            Some(path)
×
41
        } else if let Ok(cwd) = env::current_dir() {
×
42
            Some(cwd.join(path))
×
43
        } else {
44
            None
×
45
        }
46
    } else {
47
        None
60✔
48
    }
49
}
60✔
50

51
fn get_pantry_dir() -> io::Result<PathBuf> {
30✔
52
    if let Some(path) = get_PKGX_PANTRY_DIR() {
30✔
53
        Ok(path)
×
54
    } else if let Some(path) = dirs_next::data_local_dir() {
30✔
55
        Ok(path.join("pkgx/pantry"))
30✔
56
    } else {
57
        Err(io::Error::new(
×
58
            io::ErrorKind::NotFound,
×
59
            "Could not determine cache directory",
60
        ))
61
    }
62
}
30✔
63

64
fn get_pkgx_dir() -> io::Result<PathBuf> {
30✔
65
    if let Ok(path) = env::var("PKGX_DIR") {
30✔
66
        let path = PathBuf::from(path);
×
67
        if path.is_absolute() {
×
68
            return Ok(path);
×
69
        }
70
    }
30✔
71

72
    let default = dirs_next::home_dir().map(|x| x.join(".pkgx"));
30✔
73

30✔
74
    if default.clone().is_some_and(|x| x.exists()) {
30✔
75
        Ok(default.unwrap())
24✔
76
    } else if let Ok(xdg) = env::var("XDG_DATA_HOME") {
6✔
77
        Ok(PathBuf::from(xdg).join("pkgx"))
×
78
    } else {
79
        Ok(default.unwrap())
6✔
80
    }
81
}
30✔
82

83
fn get_pantry_db_file() -> io::Result<PathBuf> {
30✔
84
    if let Some(path) = get_PKGX_PANTRY_DIR() {
30✔
85
        Ok(path.join("pantry.2.db"))
×
86
    } else if let Some(path) = dirs_next::cache_dir() {
30✔
87
        Ok(path.join("pkgx/pantry.2.db"))
30✔
88
    } else {
89
        Err(io::Error::new(
×
90
            io::ErrorKind::NotFound,
×
91
            "Could not determine data directory",
92
        ))
93
    }
94
}
30✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc