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

tamada / sibling / 21342806536

26 Jan 2026 12:59AM UTC coverage: 64.338% (+2.3%) from 61.989%
21342806536

push

github

web-flow
Merge pull request #41 from tamada/release/v2.0.4

Release/v2.0.4

64 of 116 new or added lines in 5 files covered. (55.17%)

4 existing lines in 3 files now uncovered.

350 of 544 relevant lines covered (64.34%)

4.65 hits per line

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

27.78
/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(
1✔
7
    dirs: &Dirs,
1✔
8
    next: Option<Dir<'_>>,
1✔
9
    opts: &PrintingOpts,
1✔
10
) -> String {
1✔
11
    match opts.format {
1✔
NEW
12
        Format::Json => json_string(dirs, next, opts.absolute),
×
NEW
13
        Format::Csv => csv_string(dirs, next, opts.absolute),
×
NEW
14
        Format::List => list_string(dirs, next.as_ref(), opts),
×
15
        Format::Default => {
16
            if next.is_none() {
1✔
NEW
17
                no_more_dir_string(dirs, opts)
×
18
            } else {
19
                result_string_impl(dirs, next, opts)
1✔
20
            }
21
        },
22
    }
23
}
1✔
24

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

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

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

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

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

94
fn pathbuf_to_string(path: Option<&Path>, absolute: bool) -> String {
1✔
95
    match path {
1✔
96
        Some(p) => {
1✔
97
            if absolute {
1✔
98
                std::fs::canonicalize(p)
×
99
                    .unwrap()
×
100
                    .to_string_lossy()
×
101
                    .to_string()
×
102
            } else {
103
                p.to_string_lossy().to_string()
1✔
104
            }
105
        }
NEW
106
        None => String::new(),
×
107
    }
108
}
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