summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2019-09-20 10:41:31 +0300
committerLars Wirzenius <liw@liw.fi>2019-09-20 10:41:31 +0300
commit842f41c5c8f188cad1e21551c7330b2d4ab8069b (patch)
tree5a7c6271ef90b097e2788d0633220c3ffbd3abe1
parente872c2cf6417f5ce2388c19dfbb2f82118743b43 (diff)
downloadroadmap-842f41c5c8f188cad1e21551c7330b2d4ab8069b.tar.gz
Change: roadmap2dot to take input filename from command line
-rw-r--r--Cargo.toml1
-rw-r--r--src/bin/roadmap2dot.rs29
2 files changed, 21 insertions, 9 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 7500897..191e6ba 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -8,3 +8,4 @@ edition = "2018"
[dependencies]
serde_yaml = "0.8.9"
+structopt = "0.3"
diff --git a/src/bin/roadmap2dot.rs b/src/bin/roadmap2dot.rs
index 599c178..bb27a5f 100644
--- a/src/bin/roadmap2dot.rs
+++ b/src/bin/roadmap2dot.rs
@@ -1,15 +1,26 @@
use roadmap::Roadmap;
+use structopt::StructOpt;
+use std::path::PathBuf;
+use std::fs::File;
+use std::io::Read;
+
+#[derive(Debug, StructOpt)]
+#[structopt(name = "roadmap2dot", about = "Create a dot graph of a roadmap in YAML")]
+struct Opt {
+ // The input filename.
+ #[structopt(parse(from_os_str))]
+ filename: PathBuf,
+}
-fn main() {
- let r = Roadmap::from_yaml("
-first:
- label: first step
-second:
- label: the second step
- depends:
- - first
-").unwrap();
+fn main() -> Result<(), Box<dyn std::error::Error>> {
+ let opt = Opt::from_args();
+ let mut text = String::new();
+ let mut f = File::open(opt.filename)?;
+ f.read_to_string(&mut text)?;
+ let r = Roadmap::from_yaml(&text)?;
println!("{}", r.as_dot().unwrap());
+
+ Ok(())
}