diff options
| author | Bernhard Guillon <Bernhard.Guillon@begu.org> | 2025-09-16 21:37:41 +0200 |
|---|---|---|
| committer | Bernhard Guillon <Bernhard.Guillon@begu.org> | 2025-09-16 21:37:41 +0200 |
| commit | 6ef4394920ad0aa61eff8b7c9cd70fed519a42c0 (patch) | |
| tree | df4c91a4b41921b65247a84faf142468d543234d /src | |
| parent | 5ad615a08ec0eca3e4bd14aebe46c14bd20d2675 (diff) | |
| download | future-me-6ef4394920ad0aa61eff8b7c9cd70fed519a42c0.tar.gz future-me-6ef4394920ad0aa61eff8b7c9cd70fed519a42c0.zip | |
future-me: add rust prototype for the json schema
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..7248942 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,61 @@ +use serde::{Deserialize, Serialize}; +//use serde_json::Result; +use std::time::{SystemTime, UNIX_EPOCH}; +use std::{ + env::{temp_dir, var}, + fs::File, + io::Read, + process::Command, +}; +use std::fs; + +#[derive(Serialize, Deserialize)] +struct BugReport { + timestamp: String, + status: String, + title: String, + description: Vec<String>, + tags: Option<String>, + version: String +} + +fn new_bug() { + let editor = var("EDITOR").unwrap(); + let mut file_path = temp_dir(); // TODO: figgure out how to get .git dir in a save manner + file_path.push("NEW_BUG_REPORT"); + File::create(&file_path).expect("Could not create file"); + + Command::new(editor) + .arg(&file_path) + .status() + .expect("Something went wrong"); + + let mut new_bug_report = String::new(); + let _ = File::open(&file_path) + .expect("Could not open file") + .read_to_string(&mut new_bug_report); + let _ = fs::remove_file(&file_path); + let mut header = ""; + let mut description: Vec::<String> = Vec::new(); + for (i, line) in new_bug_report.lines().enumerate() { + match i { + 0 => header = line, + 1 => (), + _ => description.push(line.to_string()), + } + } + let report = BugReport { + timestamp: SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs().to_string(), + title: header.to_owned(), + description: description.to_owned(), + status: "new".to_owned(), + tags: None, + version: "v1".to_owned(), + }; + let j = serde_json::to_string(&report).unwrap(); + print!("{}", j); +} + +fn main() { + new_bug(); +} |
