From 4ecaa6999df9669cd1df09e488e616c109b769d5 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 5 Dec 2021 11:35:06 +0200 Subject: feat! add subcommand "spec" Sponsored-by: author --- obnam-benchmark.md | 2 +- src/bin/obnam-benchmark.rs | 33 ++++++++++++++++++++++++++------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/obnam-benchmark.md b/obnam-benchmark.md index e80ae91..076255d 100644 --- a/obnam-benchmark.md +++ b/obnam-benchmark.md @@ -89,7 +89,7 @@ correctly. given an installed Rust program obnam-benchmark given file spec.yaml given file expected.json -when I run obnam-benchmark spec.yaml --output spec.json +when I run obnam-benchmark spec spec.yaml --output spec.json then JSON files spec.yaml and expected.json match ``` diff --git a/src/bin/obnam-benchmark.rs b/src/bin/obnam-benchmark.rs index 617a0a3..5d4f06a 100644 --- a/src/bin/obnam-benchmark.rs +++ b/src/bin/obnam-benchmark.rs @@ -6,6 +6,17 @@ 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, @@ -23,13 +34,21 @@ fn main() { fn real_main() -> anyhow::Result<()> { let opt = Opt::from_args(); - println!("reading {}", opt.spec.display()); - let input = File::open(&opt.spec)?; - let spec: Specification = serde_yaml::from_reader(&input)?; - - println!("writing {}", opt.output.display()); - let output = File::create(&opt.output)?; - serde_json::to_writer(&output, &spec)?; + 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(()) + } +} -- cgit v1.2.1