summaryrefslogtreecommitdiffstats
path: root/src/bin/annotaterust.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/annotaterust.rs')
-rw-r--r--src/bin/annotaterust.rs49
1 files changed, 49 insertions, 0 deletions
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");
+}