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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
use anyhow::{Context, Result};
use clap::{App, ArgMatches};
use std::convert::TryInto;
fn main() -> Result<()> {
let yaml = clap::load_yaml!("main.yml");
let matches = App::from_yaml(yaml).get_matches();
match matches.subcommand() {
("combine", Some(matches)) => combine(matches),
("generate", Some(matches)) => generate(matches),
("script", Some(matches)) => script(matches),
("tarball", Some(matches)) => tarball(matches),
_ => unreachable!(),
}
}
/// Parse clap arguements into the type constructor.
macro_rules! parse(
($matches:expr => $type:ty { $( $option:tt => $setter:ident, )* }) => {
{
let mut command: $type = Default::default();
$(
if let Some(val) = $matches.value_of($option) {
command.$setter(val.try_into()?);
}
)*
command
}
}
);
fn combine(matches: &ArgMatches<'_>) -> Result<()> {
let combiner = parse!(matches => installer::Combiner {
"product-name" => product_name,
"package-name" => package_name,
"rel-manifest-dir" => rel_manifest_dir,
"success-message" => success_message,
"legacy-manifest-dirs" => legacy_manifest_dirs,
"input-tarballs" => input_tarballs,
"non-installed-overlay" => non_installed_overlay,
"work-dir" => work_dir,
"output-dir" => output_dir,
});
combiner.run().context("failed to combine installers")?;
Ok(())
}
fn generate(matches: &ArgMatches<'_>) -> Result<()> {
let generator = parse!(matches => installer::Generator {
"product-name" => product_name,
"component-name" => component_name,
"package-name" => package_name,
"rel-manifest-dir" => rel_manifest_dir,
"success-message" => success_message,
"legacy-manifest-dirs" => legacy_manifest_dirs,
"non-installed-overlay" => non_installed_overlay,
"bulk-dirs" => bulk_dirs,
"image-dir" => image_dir,
"work-dir" => work_dir,
"output-dir" => output_dir,
"compression-formats" => compression_formats,
});
generator.run().context("failed to generate installer")?;
Ok(())
}
fn script(matches: &ArgMatches<'_>) -> Result<()> {
let scripter = parse!(matches => installer::Scripter {
"product-name" => product_name,
"rel-manifest-dir" => rel_manifest_dir,
"success-message" => success_message,
"legacy-manifest-dirs" => legacy_manifest_dirs,
"output-script" => output_script,
});
scripter
.run()
.context("failed to generate installation script")?;
Ok(())
}
fn tarball(matches: &ArgMatches<'_>) -> Result<()> {
let tarballer = parse!(matches => installer::Tarballer {
"input" => input,
"output" => output,
"work-dir" => work_dir,
});
tarballer.run().context("failed to generate tarballs")?;
Ok(())
}
|