diff options
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 124 |
1 files changed, 121 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs index e070af3..91ab019 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,7 +20,8 @@ use std::fmt; use std::num::ParseIntError; use std::io::Write; use std::collections::HashMap; -use chrono::{NaiveDateTime, Utc, TimeZone}; +use chrono::{Utc, TimeZone}; +use std::env::args; #[derive(Serialize, Deserialize, Debug, Default, Clone)] struct BugReport { @@ -205,7 +206,124 @@ fn show() { } } + +//create-new-bug() { +// readonly bug="$1" +// last_ref=$(git show-ref refs/notes/devtools/future-me | cut -d ' ' -f 1) +// echo $last_ref +// if [ -n "$last_ref" ] +// then +// git read-tree $last_ref +// else +// git read-tree --empty +// fi +// +// object_id=$(echo "$1" | git hash-object -w --stdin) +// echo $object_id +// file_path=${object_id:0:2}/${object_id:2} +// git update-index --add --cacheinfo 100644 $object_id $file_path +// tree_id=$(git write-tree) +// files_to_unstage=$(git update-index --refresh | cut -d ' ' -f 1 | cut -d ':' -f 1) +// git update-index --remove $files_to_unstage +// if [ -n "$last_ref" ] +// then +// add_parent="$last_ref" +// commit_id=$(echo 'future-me: created a new bug for you' | git commit-tree $tree_id -p $add_parent) +// else +// commit_id=$(echo 'future-me: created a new bug for you' | git commit-tree $tree_id) +// fi +// git update-ref refs/notes/devtools/future-me $commit_id +//} +// +// new) +// echo create new bug "$payload" #"${*:2}" +// check-git-status +// last_tree="$(git --no-pager log -1 --format="%H" | tr --delete '\n')" +// echo $last_tree +// create-new-bug "$payload" +// git read-tree "$last_tree" +// ;; + + +fn get_current_tree() -> Result<String, GitError>{ + let cmd = Command::new("git") + .arg("log") + .arg("-1") + .arg("--format=%H") + .output() + .expect("Error with git log"); + if !cmd.status.success() { + GitError::GitLog(String::from_utf8_lossy(&cmd.stderr).to_string()); + } + let lines = String::from_utf8_lossy(&cmd.stdout); + Ok(lines.trim().to_string()) +} + +fn read_tree(tree: &str) { + let cmd = Command::new("git") + .arg("read-tree") + .arg(tree) + .output() + .expect("Error with git read-tree"); + if !cmd.status.success() { + panic!("{}", String::from_utf8_lossy(&cmd.stderr)); + } +} + +fn check_status() { + let logs = Command::new("git") + .arg("status") + .arg("--porcelain") + .output() + .expect("Error with git status"); + if !logs.status.success() { + GitError::GitLog(String::from_utf8_lossy(&logs.stderr).to_string()); + } + let lines = String::from_utf8_lossy(&logs.stdout); + for line in lines.lines() { + println!("{}", line); + if line.starts_with(['M', 'A']) { + panic!("You first need to clean you git staging status to use future-me"); + } + } +} + +fn print_usage() { + println!("usage: future-me <command>\n"); + println!("commands:"); + println!("show - shows the log"); + println!("new - enter new bug"); + println!("help - get this help"); +} + +enum Cmd{ + Show, + New, + Check, +} + +fn process_args() -> Cmd { + let myargs: Vec<String> = args().collect(); + println!("{:?}", myargs); + if myargs.len() != 2 { + print_usage(); + } + let unwraped = myargs.get(1).unwrap(); + match unwraped.as_str() { + "show" => Cmd::Show, + "new" => Cmd::New, + "check" => Cmd::Check, + _ => {print_usage(); todo!()}, + } +} + fn main() { - //new_bug(); - show(); + match process_args() { + Cmd::Show => show(), + Cmd::New => new_bug(), + Cmd::Check=> { + let tree = get_current_tree().unwrap(); + read_tree(&tree); + } + } } |
