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

dustinblackman / cargo-run-bin / 7055422475

01 Dec 2023 03:33AM UTC coverage: 59.236% (-4.5%) from 63.696%
7055422475

push

github

dustinblackman
feat: Add Windows support

12 of 27 new or added lines in 3 files covered. (44.44%)

16 existing lines in 1 file now uncovered.

279 of 471 relevant lines covered (59.24%)

12.14 hits per line

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

43.64
/src/shims.rs
1
use std::env;
2
use std::fs;
3
use std::io::Write;
4
use std::path;
5

6
use anyhow::Result;
7
use cfg_if::cfg_if;
8

9
use crate::metadata;
10

11
#[cfg(test)]
12
#[path = "shims_test.rs"]
13
mod shims_test;
14

15
#[cfg(target_family = "unix")]
NEW
16
fn create_shim(binary: &str, bin_path: path::PathBuf) -> Result<()> {
×
NEW
17
    use std::os::unix::prelude::OpenOptionsExt;
×
NEW
18

×
UNCOV
19
    let shell = env::var("SHELL")
×
UNCOV
20
        .unwrap_or("bash".to_string())
×
UNCOV
21
        .split('/')
×
UNCOV
22
        .last()
×
UNCOV
23
        .unwrap()
×
UNCOV
24
        .to_string();
×
UNCOV
25

×
UNCOV
26
    let script = format!(
×
UNCOV
27
        r#"#!/usr/bin/env {shell}
×
UNCOV
28

×
UNCOV
29
if [ ! -t 0 ]; then
×
UNCOV
30
    cat - | cargo bin {binary} "$@"
×
UNCOV
31
else
×
UNCOV
32
    cargo bin {binary} "$@"
×
UNCOV
33
fi"#
×
UNCOV
34
    );
×
35

NEW
36
    let mut f = fs::OpenOptions::new()
×
NEW
37
        .create(true)
×
NEW
38
        .write(true)
×
NEW
39
        .mode(0o770)
×
NEW
40
        .open(bin_path)?;
×
41

NEW
42
    write!(f, "{}", script)?;
×
43

NEW
44
    return Ok(());
×
NEW
45
}
×
46

47
#[cfg(not(target_family = "unix"))]
48
fn create_shim(binary: &str, bin_path: path::PathBuf) -> Result<()> {
49
    let script = format!(
50
        r#"@echo off
51
cargo bin {binary} %*
52
"#
53
    );
54

55
    let mut f = fs::OpenOptions::new()
56
        .create(true)
57
        .write(true)
58
        .open(bin_path)?;
59

60
    write!(f, "{}", script)?;
61

62
    return Ok(());
63
}
64

65
pub fn sync() -> Result<()> {
1✔
66
    let bin_dir = metadata::get_project_root()?.join(".bin/.shims");
1✔
67
    if !bin_dir.exists() {
1✔
68
        fs::create_dir_all(&bin_dir)?;
×
69
    }
1✔
70

71
    for pkg in metadata::get_binary_packages()? {
13✔
72
        let mut bin = pkg.package;
13✔
73
        if let Some(bin_target) = pkg.bin_target {
13✔
74
            bin = bin_target;
2✔
75
        }
11✔
76

77
        if bin.starts_with("cargo-") {
13✔
78
            continue;
8✔
79
        }
5✔
80

5✔
81
        let mut bin_path = bin_dir.join(&bin);
5✔
82
        bin_path.set_extension("");
5✔
83
        cfg_if! {
5✔
84
            if #[cfg(not(target_family = "unix"))] {
5✔
85
                bin_path.set_extension("cmd");
5✔
86
            }
5✔
87
        }
5✔
88
        if bin_path.exists() {
5✔
89
            continue;
5✔
90
        }
×
91

×
NEW
92
        create_shim(&bin, bin_path)?;
×
93
    }
94

95
    return Ok(());
1✔
96
}
1✔
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