File: program.rs

package info (click to toggle)
thin-provisioning-tools 1.1.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,300 kB
  • sloc: xml: 544; sh: 521; makefile: 133
file content (55 lines) | stat: -rw-r--r-- 1,266 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use anyhow::Result;
use std::path::PathBuf;

pub use crate::common::process::*;
use crate::common::test_dir::TestDir;

//------------------------------------------

pub enum ArgType {
    InputArg,
    IoOptions,
}

pub trait Program<'a> {
    fn name() -> &'a str;
    fn cmd<I>(args: I) -> Command
    where
        I: IntoIterator,
        I::Item: Into<std::ffi::OsString>;
    fn usage() -> &'a str;
    fn arg_type() -> ArgType;
    fn required_args() -> &'a [&'a str] {
        &[]
    }

    // error messages
    fn bad_option_hint(option: &str) -> String;
}

pub trait InputProgram<'a>: Program<'a> {
    fn mk_valid_input(td: &mut TestDir) -> Result<PathBuf>;

    // error messages
    fn missing_input_arg() -> &'a str;
    fn file_not_found() -> &'a str;
    fn corrupted_input() -> &'a str;
}

pub trait MetadataReader<'a>: InputProgram<'a> {}

pub trait OutputProgram<'a>: InputProgram<'a> {
    // error messages
    fn missing_output_arg() -> &'a str;
}

// programs that write existed files
pub trait MetadataWriter<'a>: OutputProgram<'a> {
    // error messages
    fn file_not_found() -> &'a str;
}

// programs that create output files (O_CREAT)
pub trait MetadataCreator<'a>: OutputProgram<'a> {}

//------------------------------------------