From 44888630b7ee1dbefa9964ca750b1622b3dc5fb0 Mon Sep 17 00:00:00 2001 From: Wesley Moore Date: Mon, 8 Jul 2019 11:30:32 +1000 Subject: Shuffle things around to use the lib from the binary --- src/bin/annotaterust.rs | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/bin/annotaterust.rs (limited to 'src/bin/annotaterust.rs') diff --git a/src/bin/annotaterust.rs b/src/bin/annotaterust.rs new file mode 100644 index 0000000..46154fe --- /dev/null +++ b/src/bin/annotaterust.rs @@ -0,0 +1,49 @@ +use std::{env, io}; +use std::fs::File; +use std::io::Read; +use std::process; +use std::collections::HashMap; + +use annotate_rust::{git, annotate::Annotation}; + +fn main() { + let mut args = env::args(); + let _ = args.next(); // executable name + + let filename = match (args.next(), args.next()) { + (Some(filename), None) => filename, + _ => { + eprintln!("Usage: dump-syntax path/to/filename.rs"); + process::exit(1); + } + }; + + let mut file = File::open(&filename).expect("Unable to open file"); + + let mut src = String::new(); + file.read_to_string(&mut src).expect("Unable to read file"); + + let syntax = syn::parse_file(&src).expect("Unable to parse file"); + println!("{:#?}", syntax); + + let output = git::crawl_git_tree(".").expect("git"); + let blobs = git::parse_ls_tree_output(&output).expect("parse"); + + let mut annotations = HashMap::new(); + annotations.insert(blobs[0].object, Annotation::Markdown { + lineno: 1, + title: "Title".to_string(), + content: "content".to_string() + }); + annotations.insert(blobs[1].object, Annotation::Link { + lineno: 1, + colno: 0, + len: 5, + to: "asdf".to_string(), + title: None, + color: None + }); + + let stdout = io::stdout(); + serde_json::to_writer_pretty(stdout, &annotations).expect("json"); +} -- cgit v1.2.3