blob: 5d4f06a83a05282773954afe6a3cb946cef7fa41 (
plain)
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
|
use obnam_benchmark::Specification;
use std::fs::File;
use std::path::PathBuf;
use std::process::exit;
use structopt::StructOpt;
#[derive(Debug, StructOpt)]
struct Opt {
#[structopt(subcommand)]
cmd: Command,
}
#[derive(Debug, StructOpt)]
enum Command {
Spec(Spec),
}
#[derive(Debug, StructOpt)]
struct Spec {
#[structopt(parse(from_os_str))]
spec: PathBuf,
#[structopt(long, parse(from_os_str))]
output: PathBuf,
}
fn main() {
if let Err(err) = real_main() {
eprintln!("ERROR: {}", err);
exit(1);
}
}
fn real_main() -> anyhow::Result<()> {
let opt = Opt::from_args();
match opt.cmd {
Command::Spec(x) => x.run()?,
}
Ok(())
}
impl Spec {
fn run(&self) -> anyhow::Result<()> {
let input = File::open(&self.spec)?;
let spec: Specification = serde_yaml::from_reader(&input)?;
let output = File::create(&self.output)?;
serde_json::to_writer(&output, &spec)?;
Ok(())
}
}
|