fixed retard commit

This commit is contained in:
Hion-V 2022-02-20 17:34:54 +01:00
parent 01f27d6476
commit b1412b4eb2

View File

@ -8,130 +8,116 @@ package;
import sys.FileSystem; import sys.FileSystem;
import Sys; import Sys;
class Main{ enum abstract AnsiColors(String) {
var C_BLACK = '\033[0;30m';
var C_RED = '\033[31m';
static var switches:Map<String,String> = [ var C_GREEN = '\033[32m';
"-v"=>"Prints the version number", var C_YELLOW = '\033[33m';
"-t"=>"Turbo mode: Skips recursively listing all content in directories" var C_BLUE = '\033[1;34m';
]; var C_MAGENTA = '\033[1;35m';
static var ansiColors:Map<String,String> = []; var C_CYAN = '\033[0;36m';
static function setupColors():Void var C_GREY = '\033[0;37m';
{ var C_WHITE = '\033[1;37m';
ansiColors['black'] = '\033[0;30m'; var C_DEFAULT = '\033[0m';
ansiColors['red'] = '\033[31m'; }
ansiColors['green'] = '\033[32m';
ansiColors['yellow'] = '\033[33m'; class Main{
ansiColors['blue'] = '\033[1;34m'; static var switches:Map<String, String> = [
ansiColors['magenta'] = '\033[1;35m'; "-v" => "Prints the version number",
ansiColors['cyan'] = '\033[0;36m'; "-t" => "Turbo mode: Skips recursively listing all content in directories"
ansiColors['grey'] = '\033[0;37m'; ];
ansiColors['white'] = '\033[1;37m';
} static var SWITCHMODE_TURBO:Bool = false;
static var SWITCHMODE_TURBO:Bool = false; static function main() {
// Store args
static function main(){ var args = Sys.args();
// Set up ansiColors // Check if we need to throw usage strings back at the user
setupColors(); if (args.length == 0) {
// Store args usage();
var args = Sys.args(); return;
// Check if we need to throw usage strings back at the user }
if(args.length == 0){ // Create arrays to hold switches and files
usage(); var _switches:Array<String> = [];
return; var files:Array<String> = [];
} // Loop through args to sort them into switches and files
// Create arrays to hold switches and files for (arg in args) {
var _switches:Array<String> = []; if (arg.charAt(0) == "-" && switches.exists(arg)) {
var files:Array<String> = []; _switches.push(arg);
// Loop through args to sort them into switches and files // Sys.println("switch found");
for(arg in args){ } else {
if(arg.charAt(0) == "-" && switches.exists(arg)){ files.push(arg);
_switches.push(arg); }
//Sys.println("switch found"); }
}
else{ // Look at switch contents
files.push(arg); if (_switches.contains("-v")) {
} Sys.println('version: ${haxe.macro.Compiler.getDefine("version")}');
} return;
}
// Look at switch contents if (_switches.contains("-t")) {
if(_switches.contains("-v")){ SWITCHMODE_TURBO = true;
Sys.println('version: ${haxe.macro.Compiler.getDefine("version")}'); }
return;
} // Good to go!
if(_switches.contains("-t")){ run(files, _switches);
SWITCHMODE_TURBO = true; // Reset color just in case
} Sys.print(C_DEFAULT);
// Good to go! Sys.exit(0);
run(files, _switches); }
// Reset color just in case
Sys.print(ansiColors['grey']); static function run(files:Array<String>, _switches:Array<String>):Void {
// Warn user about the operation they're about to perform
Sys.exit(0); Sys.println(C_RED + 'Are you ABSOLUTELY sure you want to delete the following files/ directories:' + C_DEFAULT);
var _files:Array<String> = [];
} for (file in files) {
if (FileSystem.exists(file)) {
static function run(files:Array<String>, _switches:Array<String>):Void var containingDir = FileSystem.absolutePath('$file/..');
{ var absPath = FileSystem.absolutePath('$file');
// Warn user about the operation they're about to perform var filename = absPath.substr(containingDir.length);
Sys.println(ansiColors['red'] + 'Are you ABSOLUTELY sure you want to delete the following files/ directories:' + ansiColors['grey']); Sys.println(C_YELLOW + ' - $containingDir$filename' + C_DEFAULT);
var _files:Array<String> = []; _files.push(file);
for(file in files){ } else {
if(FileSystem.exists(file)){ Sys.println(C_RED + '$file does not exist' + C_DEFAULT);
var containingDir = FileSystem.absolutePath('$file/..'); }
var absPath = FileSystem.absolutePath('$file'); }
var filename = absPath.substr(containingDir.length); Sys.println(C_WHITE + 'To confirm deletion type: "YES"' + C_DEFAULT);
Sys.println(ansiColors['yellow'] + ' - $containingDir$filename' + ansiColors['grey']);
_files.push(file); // Read user input
} var stdin = Sys.stdin();
else{ var strIn = stdin.readLine();
Sys.println(ansiColors['red'] + '$file does not exist' + ansiColors['grey']); stdin.close();
}
} // Check user input
Sys.println(ansiColors['white'] + 'To confirm deletion type: "YES"' + ansiColors['grey']); if (strIn == "YES") {
// Delete those fucking files
deleteFiles(files);
// Read user input } else {
var stdin = Sys.stdin(); // Abort
var strIn = stdin.readLine(); Sys.println('Aborting operation.');
stdin.close(); return;
}
// Check user input }
if(strIn == "YES"){
// Delete those fucking files static function usage():Void {
deleteFiles(files); Sys.println('Usage: ${haxe.macro.Compiler.getDefine("HAXE_OUTPUT_FILE")} [OPTION] [FILE]...');
} Sys.println("Safely runs rm -rf with a confirm prompt so you don't make an oopsie.");
else{ Sys.println("");
// Abort Sys.println("Available OPTIONS:");
Sys.println('Aborting operation.'); for (key in switches.keys()) {
return; Sys.println(' $key: ${switches[key]}');
} }
} // Sys.println("");
// Sys.println("Safely run rm -rf with a confirm prompt so you don´t make an oopsie");
}
static function usage():Void
{ static function deleteFiles(files:Array<String>):Void {
Sys.println('Usage: ${haxe.macro.Compiler.getDefine("HAXE_OUTPUT_FILE")} [OPTION] [FILE]...'); for (file in files) {
Sys.println("Safely runs rm -rf with a confirm prompt so you don´t make an oopsie."); Sys.print('Removing ${FileSystem.absolutePath('$file')} ...');
Sys.println(""); Sys.command('rm -rf $file');
Sys.println("Available OPTIONS:"); Sys.println('Done!');
for(key in switches.keys()){ }
Sys.println(' $key: ${switches[key]}'); Sys.println('Removed ${files.length} files');
} }
//Sys.println("");
//Sys.println("Safely run rm -rf with a confirm prompt so you don´t make an oopsie");
}
static function deleteFiles(files:Array<String>):Void
{
for(file in files){
Sys.print('Removing ${FileSystem.absolutePath('$file')} ...');
Sys.command('rm -rf $file');
Sys.println('Done!');
}
Sys.println('Removed ${files.length} files');
}
} }