From af07a5fe1d4c34f1fc01f37b86691a88d1d79af2 Mon Sep 17 00:00:00 2001 From: AnthonyMichaelTDM <68485672+AnthonyMichaelTDM@users.noreply.github.com> Date: Mon, 7 Mar 2022 12:23:58 -0800 Subject: [PATCH 1/5] start making todo list thing --- 00_Utilities/mardown_todo_rust/Cargo.toml | 8 ++ 00_Utilities/mardown_todo_rust/src/main.rs | 109 +++++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 00_Utilities/mardown_todo_rust/Cargo.toml create mode 100644 00_Utilities/mardown_todo_rust/src/main.rs diff --git a/00_Utilities/mardown_todo_rust/Cargo.toml b/00_Utilities/mardown_todo_rust/Cargo.toml new file mode 100644 index 00000000..dbf4faa3 --- /dev/null +++ b/00_Utilities/mardown_todo_rust/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "mardown_todo_rust" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/00_Utilities/mardown_todo_rust/src/main.rs b/00_Utilities/mardown_todo_rust/src/main.rs new file mode 100644 index 00000000..cd8aba3f --- /dev/null +++ b/00_Utilities/mardown_todo_rust/src/main.rs @@ -0,0 +1,109 @@ +use std::fs::{self, DirEntry, ReadDir, metadata}; +use std::fs::{File, OpenOptions}; +use std::io; +use std::io::prelude::*; +use std::path::{Path, PathBuf}; + + +//DATA +const ROOT_DIR: &str = "../../"; +const LANGUAGES: [(&str,&str); 9] = [ //first element of tuple is the language name, second element is the file extension + ("csharp", "cs"), + ("java", "java"), + ("javascript", "html"), + ("pascal", "pas"), + ("perl", "pl"), + ("python", "py"), + ("ruby", "rb"), + ("rust", "rs"), + ("vbnet", "vb") +]; +const INGORE: [&str;4] = ["../../.git","../../.vscode","../../00_Utilities","../../buildJvm"]; //folders to ignore + +fn main() { + //DATA + let langs_to_print: Vec<&str>; + let mut root_folders:Vec<_>; + + //print language - extension table + print_lang_extension_table(); + + //prompt user to input the file extensions of the languages they want the todo-lists for printed to console + println!("\na todo list with all the languages will be put into todo-list.md"); + println!("enter the file extensions from the table above for the languages you want a todo-list printed to standard output"); + println!("File extensions: (separated by spaces)"); + let mut raw_input = String::new(); + io::stdin().read_line(&mut raw_input).expect("Failed to read input"); + //parse input for valid languages, store them in langs_to_print + let raw_input = raw_input.as_str().trim().chars().filter(|c| c.is_ascii_alphabetic() || c.is_whitespace()).collect::();//filter out everything but ascii letters and spaces + langs_to_print = raw_input.split(' ')//create an iterator with all the words + .filter(|s| LANGUAGES.iter().any(|tup| tup.1.eq_ignore_ascii_case(*s))) //filter out words that aren't valid extensions (in languages) + .collect(); //collect words into vector + println!("\nwill print: {:?}", langs_to_print); + + //get all folders in ROOT_DIR + match fs::read_dir(ROOT_DIR) { + Err(why) => { + println!("! {:?}", why.kind()); + panic!("error"); + }, + Ok(paths) => { + root_folders = Vec::new(); + for path in paths { + let full_path = path.unwrap().path(); + if metadata(&full_path).unwrap().is_dir() { + println!("> {:?}", full_path); + root_folders.push(full_path); + } + } + }, + } + + //for all folders, search for the languages and extensions + /* + // Read the contents of a directory, returns `io::Result>` + match fs::read_dir(ROOT_DIR) { + Err(why) => println!("! {:?}", why.kind()), + Ok(paths) => for path in paths { + println!("> {:?}", path.unwrap().path()); + }, + } + */ +} + +/** + * print language - extension table + */ +fn print_lang_extension_table() { + println!("LANGUAGE\tFILE EXTENSION"); + println!("========\t=============="); + for tup in LANGUAGES.iter() { + match tup.0 { + "javascript" => println!("{}\t{}", tup.0,tup.1), //long ones + _ => println!("{}\t\t{}", tup.0,tup.1), + }; + } +} + +/** + * returns a vector containing paths to all files in path and subdirectories of path + */ +fn list_files(path: &Path) -> Vec { + let mut vec = Vec::new(); + _list_files(&mut vec,&path); + vec +} +fn _list_files(vec: &mut Vec, path: &Path) { + if metadata(&path).unwrap().is_dir() { + let paths = fs::read_dir(&path).unwrap(); + for path_result in paths { + let full_path = path_result.unwrap().path(); + if metadata(&full_path).unwrap().is_dir() { + _list_files(vec, &full_path); + } else { + vec.push(full_path); + } + } + } +} + From 980445f5c0dfde21ddf54bb43143f5f3d43da6b2 Mon Sep 17 00:00:00 2001 From: AnthonyMichaelTDM <68485672+AnthonyMichaelTDM@users.noreply.github.com> Date: Mon, 7 Mar 2022 20:47:50 -0800 Subject: [PATCH 2/5] todo-list maker finished --- .gitignore | 1 + 00_Utilities/mardown_todo_rust/src/main.rs | 80 +++++++++++++++++----- 2 files changed, 64 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index f4aa0b63..5d13dc44 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,4 @@ Pipfile Cargo.lock **/*.rs.bk /target +todo.md diff --git a/00_Utilities/mardown_todo_rust/src/main.rs b/00_Utilities/mardown_todo_rust/src/main.rs index cd8aba3f..e4bed021 100644 --- a/00_Utilities/mardown_todo_rust/src/main.rs +++ b/00_Utilities/mardown_todo_rust/src/main.rs @@ -1,7 +1,12 @@ -use std::fs::{self, DirEntry, ReadDir, metadata}; -use std::fs::{File, OpenOptions}; -use std::io; -use std::io::prelude::*; +use std::ffi::{OsString, OsStr}; +/** + * todo list generator for this repository, coded in rust + * + * @author Anthony Rubick + */ + +use std::fs; +use std::fs::metadata; use std::path::{Path, PathBuf}; @@ -18,17 +23,20 @@ const LANGUAGES: [(&str,&str); 9] = [ //first element of tuple is the language n ("rust", "rs"), ("vbnet", "vb") ]; -const INGORE: [&str;4] = ["../../.git","../../.vscode","../../00_Utilities","../../buildJvm"]; //folders to ignore +const OUTPUT_PATH: &str = "../../todo.md"; +//const INGORE: [&str;5] = ["../../.git","../../.vscode","../../00_Utilities","../../buildJvm","../../node_modules"]; //folders to ignore fn main() { //DATA - let langs_to_print: Vec<&str>; - let mut root_folders:Vec<_>; + let mut root_folders:Vec; + let mut output_string_1: String = String::new(); + //let mut game_list:Vec<_>; //print language - extension table print_lang_extension_table(); //prompt user to input the file extensions of the languages they want the todo-lists for printed to console + /* println!("\na todo list with all the languages will be put into todo-list.md"); println!("enter the file extensions from the table above for the languages you want a todo-list printed to standard output"); println!("File extensions: (separated by spaces)"); @@ -40,35 +48,73 @@ fn main() { .filter(|s| LANGUAGES.iter().any(|tup| tup.1.eq_ignore_ascii_case(*s))) //filter out words that aren't valid extensions (in languages) .collect(); //collect words into vector println!("\nwill print: {:?}", langs_to_print); + */ //get all folders in ROOT_DIR + root_folders = Vec::new(); match fs::read_dir(ROOT_DIR) { Err(why) => { println!("! {:?}", why.kind()); panic!("error"); }, Ok(paths) => { - root_folders = Vec::new(); for path in paths { let full_path = path.unwrap().path(); if metadata(&full_path).unwrap().is_dir() { - println!("> {:?}", full_path); root_folders.push(full_path); } } }, } + //for i in root_folders {println!("> {:?}", &i);} + //for all folders, search for the languages and extensions - /* - // Read the contents of a directory, returns `io::Result>` - match fs::read_dir(ROOT_DIR) { - Err(why) => println!("! {:?}", why.kind()), - Ok(paths) => for path in paths { - println!("> {:?}", path.unwrap().path()); - }, + root_folders = root_folders.into_iter().filter(|path| { + match fs::read_dir(path) { + Err(why) => {println!("! {:?}", why.kind()); false}, + Ok(paths) => { + paths.into_iter().filter(|f| metadata(f.as_ref().unwrap().path()).unwrap().is_dir()) //filter to only folders + .filter_map( |path| path.ok() ) //extract only the DirEntries + .any(|f| LANGUAGES.iter().any(|tup| OsString::from(tup.1).eq_ignore_ascii_case(f.file_name()))) //filter out ones that don't contain folders with the language names + } + } + }).collect(); + + //being forming output string + // for every game + // every language + ✅/⬜️ + for g in root_folders.into_iter() { + let game = g.clone(); + output_string_1 += format!( + "{}\n{}\n", //message format + g.into_os_string().into_string().unwrap().chars().filter(|c| !(*c=='.' || *c=='/')).collect::(),//get the game name + { + let mut s:String = String::new(); + //every language + ✅/⬜️ + LANGUAGES.iter().for_each(|lang| { + s += lang.0; + // + ✅/⬜️ + let paths = list_files(&game).into_iter().map(|path| path.into_os_string().into_string().unwrap()); + let paths:Vec = paths.into_iter().filter_map(|s| { + match Path::new(s.as_str()).extension().and_then(OsStr::to_str) { + None => None, + Some(s) => Some(s.to_string()), + } + }).collect(); //get all the extensions + if paths.into_iter().any(|f| f.eq(lang.1)) {//list_files(&game).iter().map(|path| path.into_os_string().into_string().unwrap()).any(|s| LANGUAGES.iter().map(|tup| Some(tup.1)).collect::>().contains(&s.split('.').next())) { + s+="✅"; + } else {s += "⬜️";} + + s += "\n"; + }); + s + } + ).as_str(); } - */ + //print output, and write output to file + println!("\n\n{}", output_string_1); + fs::write(OUTPUT_PATH, output_string_1).expect("failed to write todo list"); } /** From 537f7805bcacfb23b27aee9b2020c54e44179c5f Mon Sep 17 00:00:00 2001 From: AnthonyMichaelTDM <68485672+AnthonyMichaelTDM@users.noreply.github.com> Date: Mon, 7 Mar 2022 21:18:56 -0800 Subject: [PATCH 3/5] todo list maker new format added --- 00_Utilities/mardown_todo_rust/src/main.rs | 123 ++++++++++++++------- 1 file changed, 86 insertions(+), 37 deletions(-) diff --git a/00_Utilities/mardown_todo_rust/src/main.rs b/00_Utilities/mardown_todo_rust/src/main.rs index e4bed021..c40acc30 100644 --- a/00_Utilities/mardown_todo_rust/src/main.rs +++ b/00_Utilities/mardown_todo_rust/src/main.rs @@ -1,13 +1,13 @@ use std::ffi::{OsString, OsStr}; +use std::{fs, io}; +use std::fs::metadata; +use std::path::{Path, PathBuf}; /** * todo list generator for this repository, coded in rust * * @author Anthony Rubick */ -use std::fs; -use std::fs::metadata; -use std::path::{Path, PathBuf}; //DATA @@ -29,19 +29,29 @@ const OUTPUT_PATH: &str = "../../todo.md"; fn main() { //DATA let mut root_folders:Vec; - let mut output_string_1: String = String::new(); + let mut output_string: String = String::new(); + let format_game_first: bool; //let mut game_list:Vec<_>; //print language - extension table print_lang_extension_table(); + //ask user how they want the todo list formatted + println!("\n\t---====FORMATS====---\ngame first:\n\tGame\n\t\tLanguage ✅/⬜️\n\nlang first:\n\tLanguage\n\t\tGame ✅/⬜️\n\nmake todo list using the game first format?"); + let mut raw_input = String::new(); + io::stdin().read_line(&mut raw_input).expect("Failed to read input"); + //parse raw input + raw_input = raw_input.as_str().to_ascii_lowercase().to_string(); + match &raw_input[0..1] { + "y" => format_game_first = true, + _ => format_game_first = false, + } + //prompt user to input the file extensions of the languages they want the todo-lists for printed to console /* println!("\na todo list with all the languages will be put into todo-list.md"); println!("enter the file extensions from the table above for the languages you want a todo-list printed to standard output"); println!("File extensions: (separated by spaces)"); - let mut raw_input = String::new(); - io::stdin().read_line(&mut raw_input).expect("Failed to read input"); //parse input for valid languages, store them in langs_to_print let raw_input = raw_input.as_str().trim().chars().filter(|c| c.is_ascii_alphabetic() || c.is_whitespace()).collect::();//filter out everything but ascii letters and spaces langs_to_print = raw_input.split(' ')//create an iterator with all the words @@ -81,40 +91,79 @@ fn main() { } }).collect(); - //being forming output string - // for every game - // every language + ✅/⬜️ - for g in root_folders.into_iter() { - let game = g.clone(); - output_string_1 += format!( - "{}\n{}\n", //message format - g.into_os_string().into_string().unwrap().chars().filter(|c| !(*c=='.' || *c=='/')).collect::(),//get the game name - { - let mut s:String = String::new(); - //every language + ✅/⬜️ - LANGUAGES.iter().for_each(|lang| { - s += lang.0; - // + ✅/⬜️ - let paths = list_files(&game).into_iter().map(|path| path.into_os_string().into_string().unwrap()); - let paths:Vec = paths.into_iter().filter_map(|s| { - match Path::new(s.as_str()).extension().and_then(OsStr::to_str) { - None => None, - Some(s) => Some(s.to_string()), - } - }).collect(); //get all the extensions - if paths.into_iter().any(|f| f.eq(lang.1)) {//list_files(&game).iter().map(|path| path.into_os_string().into_string().unwrap()).any(|s| LANGUAGES.iter().map(|tup| Some(tup.1)).collect::>().contains(&s.split('.').next())) { - s+="✅"; - } else {s += "⬜️";} + if format_game_first { + //being forming output string + // for every game + // every language + ✅/⬜️ + for g in root_folders.into_iter() { + let game = g.clone(); + output_string += format!( + "{}\n\t{}\n", //message format + g.into_os_string().into_string().unwrap().chars().filter(|c| !(*c=='.' || *c=='/')).collect::(),//get the game name + { + let mut s:String = String::new(); + //every language + ✅/⬜️ + LANGUAGES.iter().for_each(|lang| { + s += lang.0; + // + ✅/⬜️ + let paths:Vec<_> = list_files(&game).into_iter().map(|path| path.into_os_string().into_string().unwrap()).collect(); + let paths:Vec = paths.into_iter().filter_map(|s| { + match Path::new(s.as_str()).extension().and_then(OsStr::to_str) { + None => None, + Some(s) => Some(s.to_string()), + } + }).collect(); //get all the extensions + if paths.into_iter().any(|f| f.eq(lang.1)) {//list_files(&game).iter().map(|path| path.into_os_string().into_string().unwrap()).any(|s| LANGUAGES.iter().map(|tup| Some(tup.1)).collect::>().contains(&s.split('.').next())) { + s+="✅"; + } else {s += "⬜️";} - s += "\n"; - }); - s - } - ).as_str(); + s += "\n\t"; + }); + s + } + ).as_str(); + } + } + else { + //being forming output string + // for every language + // every game + ✅/⬜️ + for lang in LANGUAGES.iter() { + output_string += format!( + "{}\n\t{}\n", //message format + lang.0, + { + let mut s:String = String::new(); + for g in (&root_folders).into_iter() { + //data + let game = g.clone(); + let game_name = game.into_os_string().into_string().unwrap().chars().filter(|c| !(*c=='.' || *c=='/')).collect::(); //get the game name + let paths:Vec<_> = list_files(g).into_iter().map(|path| path.into_os_string().into_string().unwrap()).collect(); //all subpaths of game + let paths:Vec = paths.into_iter().filter_map(|s| { + match Path::new(s.as_str()).extension().and_then(OsStr::to_str) { + None => None, + Some(s) => Some(s.to_string()), + } + }).collect(); //get all the extensions + + //add game name + s+= game_name.as_str(); + + //every game + ✅/⬜️ + if paths.into_iter().any(|f| f.eq(lang.1)) { + s+="✅"; + } else {s += "⬜️";} + + s += "\n\t"; + } + s + } + ).as_str(); + } } //print output, and write output to file - println!("\n\n{}", output_string_1); - fs::write(OUTPUT_PATH, output_string_1).expect("failed to write todo list"); + println!("\n\n{}", output_string); + fs::write(OUTPUT_PATH, output_string).expect("failed to write todo list"); } /** From 3ffc01b57987dbd4b365c119c631d04cce502a37 Mon Sep 17 00:00:00 2001 From: AnthonyMichaelTDM <68485672+AnthonyMichaelTDM@users.noreply.github.com> Date: Mon, 7 Mar 2022 21:23:24 -0800 Subject: [PATCH 4/5] markdown formatting added --- 00_Utilities/mardown_todo_rust/src/main.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/00_Utilities/mardown_todo_rust/src/main.rs b/00_Utilities/mardown_todo_rust/src/main.rs index c40acc30..c2838d30 100644 --- a/00_Utilities/mardown_todo_rust/src/main.rs +++ b/00_Utilities/mardown_todo_rust/src/main.rs @@ -98,12 +98,13 @@ fn main() { for g in root_folders.into_iter() { let game = g.clone(); output_string += format!( - "{}\n\t{}\n", //message format + "### {}\n\n\t{}\n", //message format g.into_os_string().into_string().unwrap().chars().filter(|c| !(*c=='.' || *c=='/')).collect::(),//get the game name { let mut s:String = String::new(); //every language + ✅/⬜️ LANGUAGES.iter().for_each(|lang| { + s+="- "; s += lang.0; // + ✅/⬜️ let paths:Vec<_> = list_files(&game).into_iter().map(|path| path.into_os_string().into_string().unwrap()).collect(); @@ -130,7 +131,7 @@ fn main() { // every game + ✅/⬜️ for lang in LANGUAGES.iter() { output_string += format!( - "{}\n\t{}\n", //message format + "### {}\n\n\t{}\n", //message format lang.0, { let mut s:String = String::new(); @@ -147,6 +148,7 @@ fn main() { }).collect(); //get all the extensions //add game name + s+="- "; s+= game_name.as_str(); //every game + ✅/⬜️ From b04b6cdd1816b070e7c9a5d8251eb2731ab8aa61 Mon Sep 17 00:00:00 2001 From: AnthonyMichaelTDM <68485672+AnthonyMichaelTDM@users.noreply.github.com> Date: Mon, 7 Mar 2022 21:23:24 -0800 Subject: [PATCH 5/5] markdown formatting added --- 00_Utilities/mardown_todo_rust/src/main.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/00_Utilities/mardown_todo_rust/src/main.rs b/00_Utilities/mardown_todo_rust/src/main.rs index c40acc30..8de38175 100644 --- a/00_Utilities/mardown_todo_rust/src/main.rs +++ b/00_Utilities/mardown_todo_rust/src/main.rs @@ -98,12 +98,13 @@ fn main() { for g in root_folders.into_iter() { let game = g.clone(); output_string += format!( - "{}\n\t{}\n", //message format + "### {}\n\n{}\n", //message format g.into_os_string().into_string().unwrap().chars().filter(|c| !(*c=='.' || *c=='/')).collect::(),//get the game name { let mut s:String = String::new(); //every language + ✅/⬜️ LANGUAGES.iter().for_each(|lang| { + s+="- "; s += lang.0; // + ✅/⬜️ let paths:Vec<_> = list_files(&game).into_iter().map(|path| path.into_os_string().into_string().unwrap()).collect(); @@ -117,7 +118,7 @@ fn main() { s+="✅"; } else {s += "⬜️";} - s += "\n\t"; + s += "\n"; }); s } @@ -130,7 +131,7 @@ fn main() { // every game + ✅/⬜️ for lang in LANGUAGES.iter() { output_string += format!( - "{}\n\t{}\n", //message format + "### {}\n\n{}\n", //message format lang.0, { let mut s:String = String::new(); @@ -147,6 +148,7 @@ fn main() { }).collect(); //get all the extensions //add game name + s+="- "; s+= game_name.as_str(); //every game + ✅/⬜️ @@ -154,7 +156,7 @@ fn main() { s+="✅"; } else {s += "⬜️";} - s += "\n\t"; + s += "\n"; } s }