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

asartalo / shfonts / 4651428220

pending completion
4651428220

push

github

Wayne Duran
ci: fixing auto merging release back to main 4

280 of 292 relevant lines covered (95.89%)

6.77 hits per line

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

100.0
/src/command/mod.rs
1
mod cli;
2
#[cfg(test)]
3
mod tests;
4
mod url_data;
5

6
use crate::{
7
    command::{
8
        cli::{Cli, Parser},
9
        url_data::{get_url_data, UrlByLine},
10
    },
11
    http,
12
    read::LinesWithEndings,
13
    result::CommonResult,
14
};
15

16
use std::collections::HashMap;
17
use std::env;
18
use std::fs;
19
use std::io::Write;
20
use std::path::PathBuf;
21
use url::Url;
22

23
fn get_output_dir(cli: &Cli) -> CommonResult<PathBuf> {
4✔
24
    match &cli.dir {
4✔
25
        Some(dir) => Ok(dir.clone()),
3✔
26
        None => Ok(env::current_dir()?),
1✔
27
    }
28
}
4✔
29

30
pub(crate) fn run() -> CommonResult<()> {
5✔
31
    let cli = Cli::parse();
5✔
32
    let path = &cli.css_path;
5✔
33
    let font_url_prefix = &cli.font_url_prefix;
5✔
34
    let output_dir = get_output_dir(&cli)?;
5✔
35

36
    println!("\nLoading {}", path);
5✔
37
    let css_response = http::get_css_file(path)?;
5✔
38
    let css_str = css_response.as_str()?;
3✔
39

40
    let font_urls = get_url_data(css_str.to_owned())?;
3✔
41
    let count = font_urls.len();
2✔
42

43
    let css_url = Url::parse(path)?;
2✔
44
    let mut replacements: HashMap<&String, String> = HashMap::new();
2✔
45

2✔
46
    let mut current = 0;
2✔
47

48
    let pluralized = if count > 1 { "file" } else { "files" };
2✔
49
    println!("Downloading {} font {}", count, pluralized);
2✔
50
    for font_url_data in &font_urls {
8✔
51
        current += 1;
7✔
52
        let font_url = &font_url_data.url;
7✔
53
        let full_url = http::get_full_url(font_url, &css_url)?;
7✔
54
        let url_str = full_url.to_string();
7✔
55
        let file_name = http::download_file(full_url, &output_dir)?;
7✔
56

57
        println!(" {}/{}\t{}", current, count, url_str);
6✔
58
        replacements.insert(font_url, format!("{}{}", font_url_prefix, file_name));
6✔
59
    }
60

61
    let css_file_path = output_dir.join("fonts.css");
1✔
62
    println!("Writing updated css file: {}", css_file_path.display());
1✔
63
    let mut css_file = fs::OpenOptions::new()
1✔
64
        .create(true)
1✔
65
        .write(true)
1✔
66
        .open(css_file_path)?;
1✔
67

68
    let urls_by_line = UrlByLine::new(&font_urls);
1✔
69

1✔
70
    let mut line_number: u32 = 0;
1✔
71
    let lines = LinesWithEndings::from(css_response.as_str()?);
1✔
72
    for line_result in lines {
49✔
73
        line_number += 1;
48✔
74
        let line = line_result;
48✔
75

76
        if let Some(items) = urls_by_line.at(line_number) {
48✔
77
            for item in items.iter().rev() {
6✔
78
                let mut line_clone = line.to_owned();
6✔
79
                let start = usize::try_from(item.location.column)? + 3;
6✔
80
                let end = start + item.url.len();
6✔
81
                line_clone.replace_range(start..end, replacements.get(&item.url).unwrap());
6✔
82

6✔
83
                css_file.write_all(line_clone.as_bytes())?;
6✔
84
            }
85
        } else {
86
            css_file.write_all(line.as_bytes())?;
42✔
87
        }
88
    }
89

90
    println!("Done.");
1✔
91

1✔
92
    Ok(())
1✔
93
}
4✔
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

© 2026 Coveralls, Inc