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

pkgxdev / pkgx / 12768583963

14 Jan 2025 01:23PM UTC coverage: 1.643% (-90.3%) from 91.907%
12768583963

Pull #1068

github

web-flow
Merge aab1de74e into 6a195bfb8
Pull Request #1068: v2

13 of 791 new or added lines in 17 files covered. (1.64%)

13 of 791 relevant lines covered (1.64%)

0.28 hits per line

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

0.0
/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 dist_url: String,
9
    pub pkgx_dir: PathBuf,
10
}
11

12
impl Config {
NEW
13
    pub fn new() -> io::Result<Self> {
×
NEW
14
        let pantry_dir = get_pantry_dir()?;
×
15
        let dist_url = get_dist_url();
NEW
16
        let pkgx_dir = get_pkgx_dir()?;
×
NEW
17
        Ok(Self {
×
NEW
18
            pantry_dir,
×
NEW
19
            dist_url,
×
20
            pkgx_dir,
21
        })
22
    }
23
}
24

NEW
25
fn get_dist_url() -> String {
×
NEW
26
    if let Ok(env_url) = env::var("PKGX_DIST_URL") {
×
27
        return env_url;
28
    }
NEW
29
    env!("PKGX_DIST_URL").to_string()
×
30
}
31

NEW
32
fn get_pantry_dir() -> io::Result<PathBuf> {
×
NEW
33
    if let Ok(env_dir) = env::var("PKGX_PANTRY_DIR") {
×
34
        let path = PathBuf::from(env_dir);
35
        if !path.is_absolute() {
NEW
36
            return Ok(env::current_dir()?.join(path));
×
37
        } else {
NEW
38
            return Ok(path);
×
39
        }
40
    }
NEW
41
    Ok(dirs_next::cache_dir().unwrap().join("pkgx/pantry"))
×
42
}
43

NEW
44
fn get_pkgx_dir() -> io::Result<PathBuf> {
×
NEW
45
    if let Ok(env_dir) = env::var("PKGX_DIR") {
×
46
        let path = PathBuf::from(env_dir);
47
        if !path.is_absolute() {
NEW
48
            return Ok(env::current_dir()?.join(path));
×
49
        } else {
NEW
50
            return Ok(path);
×
51
        }
52
    }
53
    #[cfg(target_os = "macos")]
54
    return Ok(dirs_next::home_dir().unwrap().join(".pkgx"));
55
    #[cfg(target_os = "linux")]
56
    return Ok(dirs_next::home_dir().unwrap().join(".pkgx"));
57
    #[cfg(not(any(target_os = "macos", target_os = "linux")))]
58
    panic!("Unsupported platform")
59
}
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