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

tamada / totebag / 10414561419

16 Aug 2024 04:16AM UTC coverage: 81.322% (-0.1%) from 81.417%
10414561419

push

github

web-flow
Merge pull request #34 from tamada/release/v0.6.0

Release/v0.6.0

275 of 322 new or added lines in 12 files covered. (85.4%)

2 existing lines in 1 file now uncovered.

1206 of 1483 relevant lines covered (81.32%)

6.94 hits per line

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

79.31
/src/cli.rs
1
use std::path::PathBuf;
2
use clap::{Parser, ValueEnum};
3

4
pub type Result<T> = std::result::Result<T, ToteError>;
5

6
#[derive(Parser, Debug)]
7
#[clap(
8
    version, author, about,
9
    arg_required_else_help = true,
10
)]
11
pub struct CliOpts {
12
    #[clap(short = 'm', long = "mode", default_value_t = RunMode::Auto, value_name = "MODE", required = false, ignore_case = true, value_enum, help = "Mode of operation.")]
1✔
13
    pub mode: RunMode,
×
14
    #[clap(short = 'o', short_alias = 'd', long = "output", alias = "dest", value_name = "DEST", required = false, help = "Output file in archive mode, or output directory in extraction mode")]
15
    pub output: Option<PathBuf>,
16
    #[clap(long = "to-archive-name-dir", help = "extract files to DEST/ARCHIVE_NAME directory (extract mode).", default_value_t = false)]
1✔
17
    pub to_archive_name_dir: bool,
×
18

19
    #[clap(
20
        short = 'C', long = "dir", value_name = "DIR", required = false,
21
        default_value = ".", help = "Specify the base directory for archiving or extracting."
22
    )]
NEW
23
    pub base_dir: PathBuf,
×
24

25
    #[clap(short = 'n', long = "no-recursive", help = "No recursive directory (archive mode).", default_value_t = false)]
1✔
26
    pub no_recursive: bool,
×
27
    #[clap(short = 'v', long = "verbose", help = "Display verbose output.", default_value_t = false)]
1✔
28
    pub verbose: bool,
×
29
    #[clap(long, help = "Overwrite existing files.")]
30
    pub overwrite: bool,
×
31
    #[clap(value_name = "ARGUMENTS", help = r###"List of files or directories to be processed.
32
If archive mode, the archive file name can specify at the first argument.
33
If the frist argument was not the archive name, the default archive name `totebag.zip` is applied.
34
"###)]
35
    pub args: Vec<PathBuf>,
5✔
36
}
37

38
#[derive(Debug, Clone, ValueEnum, PartialEq, Copy)]
39
pub enum RunMode {
40
    Auto,
41
    Archive,
42
    Extract,
43
    List,
44
}
45

46
#[derive(Debug)]
47
pub enum ToteError {
48
    NoArgumentsGiven,
49
    FileNotFound(PathBuf),
50
    FileExists(PathBuf),
51
    IO(std::io::Error),
52
    Archiver(String),
53
    UnsupportedFormat(String),
54
    UnknownFormat(String),
55
    Unknown(String),
56
    Fatal(Box<dyn std::error::Error>)
57
}
58

59
#[cfg(test)]
60
mod tests {
61
    use clap::Parser;
62

63
    use super::*;
64

65
    #[test]
66
    fn test_find_mode() {
1✔
67
        let mut cli1 = CliOpts::parse_from(&["totebag_test", "src", "LICENSE", "README.md", "Cargo.toml"]);
1✔
68
        let r1 = cli1.run_mode();
1✔
69
        assert!(r1.is_ok());
1✔
70
        assert_eq!(r1.unwrap(), RunMode::Archive);
1✔
71

72
        let mut cli2 = CliOpts::parse_from(&["totebag_test", "src", "LICENSE", "README.md", "hoge.zip"]);
1✔
73
        let r2 = cli2.run_mode();
1✔
74
        assert!(r2.is_ok());
1✔
75
        assert_eq!(cli2.run_mode().unwrap(), RunMode::Archive);
1✔
76

77
        let mut cli3 = CliOpts::parse_from(&["totebag_test", "src.zip", "LICENSE.tar", "README.tar.bz2", "hoge.rar"]);
1✔
78
        let r3 = cli3.run_mode();
1✔
79
        assert!(r3.is_ok());
1✔
80
        assert_eq!(cli3.run_mode().unwrap(), RunMode::Extract);
1✔
81

82
        let mut cli4 = CliOpts::parse_from(&["totebag_test", "src.zip", "LICENSE.tar", "README.tar.bz2", "hoge.rar", "--mode", "list"]);
1✔
83
        let r4 = cli3.run_mode();
1✔
84
        assert!(r4.is_ok());
1✔
85
        assert_eq!(cli4.run_mode().unwrap(), RunMode::List);
1✔
86
    }
1✔
87
}
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