mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-26 12:51:29 -08:00
todo-list maker finished
This commit is contained in:
@@ -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<PathBuf>;
|
||||
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<Vec<Path>>`
|
||||
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::<String>(),//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<String> = 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::<Vec<_>>().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");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user