-
Notifications
You must be signed in to change notification settings - Fork 96
/
Copy pathcompression_type.rs
43 lines (37 loc) · 1.2 KB
/
compression_type.rs
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
use argparse::{ArgumentParser, StoreConst};
#[cfg(feature="containers")]
use crate::capsule::packages as capsule;
#[derive(Clone, Copy, Debug)]
pub enum CompressionType {
Gzip,
Bzip2,
Xz,
}
impl CompressionType {
pub fn get_short_option(&self) -> &str {
match *self {
CompressionType::Gzip => "-z",
CompressionType::Bzip2 => "-j",
CompressionType::Xz => "-J",
}
}
#[cfg(feature="containers")]
pub fn get_capsule_feature(&self) -> capsule::Feature {
match *self {
CompressionType::Gzip => capsule::Gzip,
CompressionType::Bzip2 => capsule::Bzip2,
CompressionType::Xz => capsule::Xz,
}
}
}
pub fn compression_type<'x>(ap: &mut ArgumentParser<'x>,
compression_type: &'x mut Option<CompressionType>)
{
ap.refer(compression_type)
.add_option(&["-z", "--gzip"], StoreConst(Some(CompressionType::Gzip)),
"Filter the image through gzip.")
.add_option(&["-j", "--bzip2"], StoreConst(Some(CompressionType::Bzip2)),
"Filter the image through bzip2.")
.add_option(&["-J", "--xz"], StoreConst(Some(CompressionType::Xz)),
"Filter the image through xz.");
}