Skip to content

Commit

Permalink
Merge pull request #17 from tapishr/tr/user_messages
Browse files Browse the repository at this point in the history
Add relevant user messaging
  • Loading branch information
tapishr authored Jan 4, 2023
2 parents 0694daa + dc6d83f commit 59ee543
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
20 changes: 18 additions & 2 deletions devprofiler/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use std::process;
use std::path::Path;
use serde::Serialize;
use std::collections::HashSet;
use std::io::Write;
use std::io;

#[derive(Debug, Serialize, Default)]
struct UserAlias {
Expand All @@ -21,7 +23,14 @@ struct UserAlias {
fn process_repos(user_paths: Vec::<String>, einfo: &mut RuntimeInfo, writer: &mut OutputWriter) -> Vec::<String> {
let mut valid_repo = 0;
let mut all_aliases = HashSet::<String>::new();
let num_user_path = user_paths.len();
let mut count = 0;
// TODO - optimize count and iterating of vector user_path, get index in for loop
println!("");
for p in user_paths {
count += 1;
print!("Scanning [{count}/{num_user_path}] \r");
let _res = io::stdout().flush();
let ranalyzer_res = RepoAnalyzer::new(p.as_str().as_ref());
match ranalyzer_res {
Ok(ranalyzer) => {
Expand All @@ -42,6 +51,7 @@ fn process_repos(user_paths: Vec::<String>, einfo: &mut RuntimeInfo, writer: &mu
}
}
}
println!("");
if valid_repo == 0 {
let err_line = "Unable to parse any provided repo(s)";
eprintln!("{err_line}");
Expand All @@ -62,12 +72,16 @@ fn process_aliases(alias_vec: Vec::<String>, einfo: &mut RuntimeInfo, writer: &m
Err(writer_err) => {
eprintln!("Unable to record user aliases in output file : {writer_err}");
einfo.record_err(writer_err.to_string().as_str().as_ref());
let _res = writer.finish(); // result doesn't matter since already in error
process::exit(1);
}
}
}
Err(error) => {
eprintln!("Unable to process user aliases : {:?}", error);
einfo.record_err(error.to_string().as_str().as_ref());
einfo.record_err(error.to_string().as_str().as_ref());
let _res = writer.finish(); // result doesn't matter since already in error
process::exit(1);
}
}
}
Expand All @@ -88,7 +102,9 @@ fn main() {
process_aliases(alias_vec, einfo, writer_mut);
let _res = einfo.write_runtime_info(writer_mut);
match writer.finish() {
Ok(_) => {},
Ok(_) => {
println!("Profile generated as devprofile.jsonl.gz, proceed to https://devprofiler.tech/upload to upload!");
},
Err(error) => {
eprintln!("Unable to write to output : {error}");
}
Expand Down
6 changes: 4 additions & 2 deletions devprofiler/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ impl UserInput {

pub fn repo_selection(options: Vec::<String>) -> InquireResult<Vec::<String>>{
MultiSelect::new(
"Select relevant repo(s)", options)
(format!("Select relevant repo(s) out of {} repo(s)", options.len())).as_str(),
options)
.with_validator(|a: &[ListOption<&String>]| {
if a.len() < 1 {
return Ok(Validation::Invalid("Please select at least one repo".into()));
Expand All @@ -27,7 +28,8 @@ impl UserInput {

pub fn alias_selector(options: Vec::<String>) -> InquireResult<Vec::<String>>{
MultiSelect::new(
"Select your email aliases", options)
(format!("Select your email alias(es) out of {} alias(es)", options.len())).as_str(),
options)
.with_validator(|a: &[ListOption<&String>]| {
if a.len() < 1 {
return Ok(Validation::Invalid("Please select at least one alias".into()));
Expand Down
22 changes: 22 additions & 0 deletions devprofiler/src/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use std::path::PathBuf;
use walkdir::WalkDir;
use crate::observer::RuntimeInfo;
use crate::writer::OutputWriter;
use std::io;
use std::io::Write;

pub struct RepoScanner {
scanpath: PathBuf
Expand All @@ -15,6 +17,9 @@ impl RepoScanner {
pub fn scan(&self, einfo: &mut RuntimeInfo, writer: &mut OutputWriter) -> Vec<String>{
let walker = WalkDir::new(self.scanpath.as_path()).into_iter();
let mut repo_paths = Vec::<String>::new();
let mut scan_err = false;
println!("");
let mut count = 0;
for entry in walker.filter_map(|elem| {
if elem.is_err() {
let err_str = elem.err().expect("Checked, is err")
Expand All @@ -23,6 +28,7 @@ impl RepoScanner {
match writer.write_io_err(&err_str) {
Ok(_) => {},
Err(error) => {
scan_err = true;
einfo.record_err(
error.to_string().as_str().as_ref());
}
Expand All @@ -34,6 +40,8 @@ impl RepoScanner {
}
})
{
count += 1;
Self::print_progress(count);
let path = entry.path();
if path.ends_with(".git") {
repo_paths.push(
Expand All @@ -43,6 +51,20 @@ impl RepoScanner {
.to_string());
}
}
if scan_err {
eprintln!("Some directories were inaccessible. I/O errors are detailed in io_errors.txt");
}
repo_paths
}

fn print_progress(count: i64) {
let mut v = vec!["Scanning directories "];
if count % 4 == 0 {v.push("/");}
if count % 4 == 1 {v.push("-");}
if count % 4 == 2 {v.push("\\");}
if count % 4 == 3 {v.push("-");}
v.push(" \r");
print!("{}", v.concat());
let _res = io::stdout().flush();
}
}

0 comments on commit 59ee543

Please sign in to comment.