-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
20dc006
commit a621f17
Showing
12 changed files
with
198 additions
and
88 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,105 @@ | ||
use std::time::SystemTime; | ||
use std::path::PathBuf; | ||
|
||
use crate::internal::config::config; | ||
use crate::internal::file::hash; | ||
use crate::internal::git::repo; | ||
use crate::internal::git::{self, repo}; | ||
use crate::internal::log::json; | ||
use crate::internal::meta::{file, parse}; | ||
|
||
#[derive(Debug)] | ||
pub struct JsonFileResult { | ||
pub path: String, | ||
pub path: PathBuf, | ||
pub status: String, | ||
pub file_size: u64, | ||
pub file_hash: String, | ||
pub time_stamp: SystemTime, | ||
pub time_stamp: String, | ||
pub saved_by: String, | ||
pub message: String | ||
} | ||
|
||
pub fn run_status_cmd(files: &Vec<PathBuf>) { | ||
|
||
// struct JsonResult { | ||
// files: Vec<JsonFileResult>, | ||
// errors:Vec<json::JsonIssue> | ||
// } | ||
|
||
// impl JsonResult { | ||
// fn add_file(&mut self, file_result: JsonFileResult) { | ||
// self.files.push(file_result); | ||
// } | ||
|
||
// fn add_error(&mut self, json_issue: json::JsonIssue) { | ||
// self.errors.push(json_issue); | ||
// } | ||
// } // impl | ||
|
||
pub fn run_status_cmd(files: &Vec<String>) -> Result<Vec<JsonFileResult>, std::io::Error> { | ||
|
||
let mut json_logger: Vec<JsonFileResult> = Vec::new(); | ||
|
||
let mut meta_paths: Vec<PathBuf> = Vec::new(); | ||
|
||
//iIf no arguments are provided, get the status of all files in the current git repository | ||
if files.is_empty() { | ||
// Get git root | ||
let git_repo = match repo::get_nearest_repo_dir(&PathBuf::from(".")) { | ||
Ok(git_repo) => { | ||
// json | ||
git_repo | ||
} | ||
Err(e) => { | ||
// json | ||
return Err(e) | ||
} | ||
}; | ||
|
||
// get config | ||
match config::read(&git_repo) { | ||
Ok(config) => config, | ||
Err(_) => return Err(std::io::Error::other("devious is not initialized")), | ||
}; | ||
|
||
// get meta files | ||
meta_paths = parse::get_all_meta_files(git_repo); | ||
} // if doing all files | ||
else { | ||
meta_paths = parse::parse_globs(files); | ||
} // else specific files | ||
|
||
if meta_paths.is_empty() {return Ok(json_logger)} | ||
|
||
json_logger = meta_paths.into_iter().map(|path| { | ||
// get relative path | ||
let rel_path = repo::get_relative_path(&PathBuf::from("."), &path).expect("couldn't get relative path"); | ||
|
||
// get file info | ||
let metadata = file::load(&path).expect("couldn't get metadata"); | ||
|
||
// get whether file was hashable and file hash | ||
let file_hash_result = hash::get_file_hash(&path); | ||
|
||
let mut file_hash = String::from("placeholder"); | ||
if file_hash_result.is_ok() {file_hash = file_hash_result.unwrap()} | ||
// else, file_hash_result was an error, so stick with the nonsense default value so they don't match | ||
|
||
// asign status: not-present by default | ||
let mut status = String::from("out-of-date"); | ||
if !path.exists() {status = String::from("not-present")} | ||
else if file_hash == metadata.file_hash { | ||
status = String::from("up-to-date") | ||
} | ||
// else, the file exists, but the hash isn't up to date, so still with default: out-of-date | ||
|
||
// assemble info into JsonFileResult | ||
JsonFileResult{ | ||
path: rel_path, | ||
status: status, | ||
file_size: metadata.file_size, | ||
file_hash: metadata.file_hash, | ||
time_stamp: metadata.time_stamp, | ||
saved_by: metadata.saved_by, | ||
message: metadata.message | ||
} | ||
}).collect::<Vec<JsonFileResult>>(); | ||
|
||
Ok(json_logger) | ||
} // run_status_cmd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod json; | ||
pub mod json; | ||
pub mod pretty; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use crate::internal::log::json; | ||
|
||
pub fn print(string: String) { | ||
if json::JSON_LOGGING {return} | ||
|
||
println!("{}", string) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"file_hash": "71fe44583a6268b56139599c293aeb854e5c5a9908eca00105d81ad5e22b7bb6", | ||
"file_size": 445, | ||
"time_stamp": "2024-03-28 10:10:22.930945979 -04:00", | ||
"time_stamp": "2024-03-28 15:02:29.963093889 -04:00", | ||
"message": "derived DA files", | ||
"saved_by": "jenna" | ||
} |
Oops, something went wrong.