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

tamada / sibling / 21935126510

12 Feb 2026 05:44AM UTC coverage: 61.863% (-2.5%) from 64.338%
21935126510

Pull #44

github

tamada
refactor: improve directory change handling and error logging in path resolution
Pull Request #44: refactor: reorganize code structure and update dependencies for improved functionality

136 of 248 new or added lines in 6 files covered. (54.84%)

3 existing lines in 2 files now uncovered.

425 of 687 relevant lines covered (61.86%)

4.17 hits per line

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

22.22
/cli/src/printer.rs
1
use std::path::Path;
2

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

6
pub(crate) fn result_string(dirs: &Dirs, next: Option<Dir<'_>>, opts: &PrintingOpts) -> String {
1✔
7
    match opts.format {
1✔
8
        Format::Json => json_string(dirs, next, opts.absolute),
×
9
        Format::Csv => csv_string(dirs, next, opts.absolute),
×
10
        Format::List => list_string(dirs, next.as_ref(), opts),
×
11
        Format::Default => {
12
            if next.is_none() {
1✔
13
                no_more_dir_string(dirs, opts)
×
14
            } else {
15
                result_string_impl(dirs, next, opts)
1✔
16
            }
17
        }
18
    }
19
}
1✔
20

21
fn json_string(dirs: &Dirs, next: Option<Dir<'_>>, absolute: bool) -> String {
×
22
    let current = dirs.current();
×
NEW
23
    let next_path = next
×
NEW
24
        .as_ref()
×
NEW
25
        .map(|n| pathbuf_to_string(Some(n.path()), absolute, dirs.on_dirs));
×
UNCOV
26
    format!(
×
27
        r#"{{"current":{{"path":"{}","index":{}}},"next":{{"path":"{}","index":{}}},"total":{}}}"#,
NEW
28
        pathbuf_to_string(Some(dirs.current().path()), absolute, dirs.on_dirs),
×
29
        current.index() + 1,
×
30
        next_path.unwrap_or_default(),
×
31
        next.map_or(-1, |n| i32::try_from(n.index()).unwrap() + 1),
×
32
        dirs.len()
×
33
    )
34
}
×
35

36
fn csv_string(dirs: &Dirs, next: Option<Dir<'_>>, absolute: bool) -> String {
×
37
    let current = dirs.current();
×
38
    format!(
×
39
        r#""{}","{}",{},{},{}"#,
NEW
40
        pathbuf_to_string(Some(dirs.current().path()), absolute, dirs.on_dirs),
×
NEW
41
        pathbuf_to_string(next.as_ref().map(Dir::path), absolute, dirs.on_dirs),
×
42
        current.index() + 1,
×
43
        next.map_or(-1, |n| i32::try_from(n.index()).unwrap() + 1),
×
44
        dirs.len()
×
45
    )
46
}
×
47

48
fn no_more_dir_string(dirs: &Dirs, opts: &PrintingOpts) -> String {
×
49
    if opts.parent {
×
NEW
50
        pathbuf_to_string(Some(dirs.parent()), opts.absolute, dirs.on_dirs)
×
51
    } else {
52
        String::from("no more sibling directory")
×
53
    }
54
}
×
55

56
fn list_string(dirs: &Dirs, next: Option<&Dir<'_>>, opts: &PrintingOpts) -> String {
×
57
    let mut result = vec![];
×
58
    let current = dirs.current();
×
59
    let next_index = next.map_or(-1, |n| i32::try_from(n.index()).unwrap());
×
60
    for (i, dir) in dirs.directories().enumerate() {
×
61
        let prefix = if i32::try_from(i) == Ok(next_index) {
×
62
            "> "
×
63
        } else if i == current.index() {
×
64
            "* "
×
65
        } else {
66
            "  "
×
67
        };
68
        result.push(format!(
×
69
            "{:>4} {}{}",
70
            i + 1,
×
71
            prefix,
NEW
72
            pathbuf_to_string(Some(dir), opts.absolute, dirs.on_dirs)
×
73
        ));
74
    }
75
    result.join("\n")
×
76
}
×
77

78
fn result_string_impl(dirs: &Dirs, next: Option<Dir<'_>>, opts: &PrintingOpts) -> String {
1✔
79
    if opts.progress {
1✔
80
        format!(
×
81
            "{} ({}/{})",
NEW
82
            pathbuf_to_string(next.as_ref().map(Dir::path), opts.absolute, dirs.on_dirs),
×
83
            next.map_or(-1, |n| i32::try_from(n.index()).unwrap()) + 1,
×
84
            dirs.len()
×
85
        )
86
    } else {
87
        pathbuf_to_string(next.as_ref().map(Dir::path), opts.absolute, dirs.on_dirs).to_string()
1✔
88
    }
89
}
1✔
90

91
pub(crate) fn pathbuf_to_string(path: Option<&Path>, absolute: bool, on_dirs: bool) -> String {
1✔
92
    match path {
1✔
93
        Some(p) => {
1✔
94
            if absolute {
1✔
NEW
95
                match std::fs::canonicalize(p) {
×
NEW
96
                    Ok(path) => path.to_string_lossy().to_string(),
×
NEW
97
                    Err(e) => {
×
NEW
98
                        log::error!("Failed to get canonical path for {p:?}: {e}");
×
NEW
99
                        p.to_string_lossy().to_string()
×
100
                    },
101
                }
102
            } else if on_dirs && !p.is_absolute() {
1✔
NEW
103
                Path::new("..").join(p).to_string_lossy().to_string()
×
104
            } else {
105
                p.to_string_lossy().to_string()
1✔
106
            }
107
        }
108
        None => String::new(),
×
109
    }
110
}
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