summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-12-05 11:35:06 +0200
committerLars Wirzenius <liw@liw.fi>2021-12-05 11:35:06 +0200
commit4ecaa6999df9669cd1df09e488e616c109b769d5 (patch)
treed609f27501a2626647f0b42832492178e940de73
parent131e0f8fec6bbce21dc66fbdd5f2140834199cf2 (diff)
downloadobnam-benchmark-4ecaa6999df9669cd1df09e488e616c109b769d5.tar.gz
feat! add subcommand "spec"
Sponsored-by: author
-rw-r--r--obnam-benchmark.md2
-rw-r--r--src/bin/obnam-benchmark.rs33
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(())
+ }
+}