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

tamada / sibling / 16362892246

18 Jul 2025 05:23AM UTC coverage: 59.504% (-10.8%) from 70.292%
16362892246

Pull #38

github

tamada
refactor: replace build_nexter function with NexterFactory::build for consistency
Pull Request #38: Release/v2.0.1

244 of 407 new or added lines in 5 files covered. (59.95%)

288 of 484 relevant lines covered (59.5%)

3.64 hits per line

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

32.31
/cli/src/printer.rs
1
use std::path::PathBuf;
2

3
use crate::cli::PrintingOpts;
4
use sibling::{Dir, Dirs, Result};
5

6
pub(crate) fn result_string(
1✔
7
    dirs: &Dirs,
1✔
8
    next: Option<Dir<'_>>,
1✔
9
    opts: &PrintingOpts,
1✔
10
) -> Result<String> {
1✔
11
    if opts.csv {
1✔
NEW
12
        csv_string(dirs, next, opts.absolute)
×
13
    } else if next.is_some() && next.clone().unwrap().is_last_item() {
1✔
NEW
14
        no_more_dir_string(dirs, opts)
×
15
    } else if opts.list {
1✔
NEW
16
        list_string(dirs, next, opts)
×
17
    } else {
18
        result_string_impl(dirs, next, opts)
1✔
19
    }
20
}
1✔
21

NEW
22
fn csv_string(dirs: &Dirs, next: Option<Dir<'_>>, absolute: bool) -> Result<String> {
×
NEW
23
    let current = dirs.current();
×
NEW
24
    Ok(format!(
×
NEW
25
        r##""{}","{}",{},{},{}"##,
×
NEW
26
        pathbuf_to_string(Some(dirs.current().path()), absolute),
×
NEW
27
        pathbuf_to_string(next.clone().map(|p| p.path()), absolute),
×
NEW
28
        current.index() + 1,
×
NEW
29
        next.map(|n| n.index() as i32 + 1).unwrap_or(-1),
×
NEW
30
        dirs.len()
×
31
    ))
NEW
32
}
×
33

NEW
34
fn no_more_dir_string(dirs: &Dirs, opts: &PrintingOpts) -> Result<String> {
×
NEW
35
    if opts.parent {
×
NEW
36
        Ok(pathbuf_to_string(Some(dirs.parent()), opts.absolute))
×
37
    } else {
NEW
38
        Ok(String::from("no more sibling directory"))
×
39
    }
NEW
40
}
×
41

NEW
42
fn list_string(dirs: &Dirs, next: Option<Dir<'_>>, opts: &PrintingOpts) -> Result<String> {
×
NEW
43
    let mut result = vec![];
×
NEW
44
    let current = dirs.current();
×
NEW
45
    let next_index = next.clone().map(|n| n.index() as i32).unwrap_or(-1);
×
NEW
46
    for (i, dir) in dirs.directories().enumerate() {
×
NEW
47
        let prefix = if i as i32 == next_index {
×
NEW
48
            "> "
×
NEW
49
        } else if i == current.index() {
×
NEW
50
            "* "
×
51
        } else {
NEW
52
            "  "
×
53
        };
NEW
54
        result.push(format!(
×
NEW
55
            "{:>4} {}{}",
×
NEW
56
            i + 1,
×
57
            prefix,
NEW
58
            pathbuf_to_string(Some(dir.to_path_buf()), opts.absolute)
×
59
        ));
60
    }
NEW
61
    Ok(result.join("\n"))
×
NEW
62
}
×
63

64
fn result_string_impl(dirs: &Dirs, next: Option<Dir<'_>>, opts: &PrintingOpts) -> Result<String> {
1✔
65
    let r = if opts.progress {
1✔
NEW
66
        format!(
×
NEW
67
            "{} ({}/{})",
×
NEW
68
            pathbuf_to_string(next.clone().map(|n| n.path()), opts.absolute),
×
NEW
69
            next.map(|n| n.index() as i32).unwrap_or(-1) + 1,
×
NEW
70
            dirs.len()
×
71
        )
72
    } else {
73
        pathbuf_to_string(next.map(|n| n.path()), opts.absolute).to_string()
1✔
74
    };
75
    Ok(r)
1✔
76
}
1✔
77

78
fn pathbuf_to_string(path: Option<PathBuf>, absolute: bool) -> String {
1✔
79
    match path {
1✔
80
        Some(p) => {
1✔
81
            if absolute {
1✔
NEW
82
                std::fs::canonicalize(p)
×
NEW
83
                    .unwrap()
×
NEW
84
                    .to_string_lossy()
×
NEW
85
                    .to_string()
×
86
            } else {
87
                p.to_string_lossy().to_string()
1✔
88
            }
89
        }
NEW
90
        None => "".to_string(),
×
91
    }
92
}
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

© 2026 Coveralls, Inc