fixed retard commit
This commit is contained in:
parent
01f27d6476
commit
b1412b4eb2
66
src/Main.hx
66
src/Main.hx
@ -8,32 +8,28 @@ package;
|
||||
import sys.FileSystem;
|
||||
import Sys;
|
||||
|
||||
enum abstract AnsiColors(String) {
|
||||
var C_BLACK = '\033[0;30m';
|
||||
var C_RED = '\033[31m';
|
||||
var C_GREEN = '\033[32m';
|
||||
var C_YELLOW = '\033[33m';
|
||||
var C_BLUE = '\033[1;34m';
|
||||
var C_MAGENTA = '\033[1;35m';
|
||||
var C_CYAN = '\033[0;36m';
|
||||
var C_GREY = '\033[0;37m';
|
||||
var C_WHITE = '\033[1;37m';
|
||||
var C_DEFAULT = '\033[0m';
|
||||
}
|
||||
|
||||
class Main{
|
||||
|
||||
|
||||
static var switches:Map<String, String> = [
|
||||
"-v" => "Prints the version number",
|
||||
"-t" => "Turbo mode: Skips recursively listing all content in directories"
|
||||
];
|
||||
static var ansiColors:Map<String,String> = [];
|
||||
static function setupColors():Void
|
||||
{
|
||||
ansiColors['black'] = '\033[0;30m';
|
||||
ansiColors['red'] = '\033[31m';
|
||||
ansiColors['green'] = '\033[32m';
|
||||
ansiColors['yellow'] = '\033[33m';
|
||||
ansiColors['blue'] = '\033[1;34m';
|
||||
ansiColors['magenta'] = '\033[1;35m';
|
||||
ansiColors['cyan'] = '\033[0;36m';
|
||||
ansiColors['grey'] = '\033[0;37m';
|
||||
ansiColors['white'] = '\033[1;37m';
|
||||
}
|
||||
|
||||
static var SWITCHMODE_TURBO:Bool = false;
|
||||
|
||||
static function main() {
|
||||
// Set up ansiColors
|
||||
setupColors();
|
||||
// Store args
|
||||
var args = Sys.args();
|
||||
// Check if we need to throw usage strings back at the user
|
||||
@ -49,8 +45,7 @@ class Main{
|
||||
if (arg.charAt(0) == "-" && switches.exists(arg)) {
|
||||
_switches.push(arg);
|
||||
// Sys.println("switch found");
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
files.push(arg);
|
||||
}
|
||||
}
|
||||
@ -67,31 +62,27 @@ class Main{
|
||||
// Good to go!
|
||||
run(files, _switches);
|
||||
// Reset color just in case
|
||||
Sys.print(ansiColors['grey']);
|
||||
Sys.print(C_DEFAULT);
|
||||
|
||||
Sys.exit(0);
|
||||
|
||||
}
|
||||
|
||||
static function run(files:Array<String>, _switches:Array<String>):Void
|
||||
{
|
||||
static function run(files:Array<String>, _switches:Array<String>):Void {
|
||||
// Warn user about the operation they're about to perform
|
||||
Sys.println(ansiColors['red'] + 'Are you ABSOLUTELY sure you want to delete the following files/ directories:' + ansiColors['grey']);
|
||||
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)) {
|
||||
var containingDir = FileSystem.absolutePath('$file/..');
|
||||
var absPath = FileSystem.absolutePath('$file');
|
||||
var filename = absPath.substr(containingDir.length);
|
||||
Sys.println(ansiColors['yellow'] + ' - $containingDir$filename' + ansiColors['grey']);
|
||||
Sys.println(C_YELLOW + ' - $containingDir$filename' + C_DEFAULT);
|
||||
_files.push(file);
|
||||
}
|
||||
else{
|
||||
Sys.println(ansiColors['red'] + '$file does not exist' + ansiColors['grey']);
|
||||
} else {
|
||||
Sys.println(C_RED + '$file does not exist' + C_DEFAULT);
|
||||
}
|
||||
}
|
||||
Sys.println(ansiColors['white'] + 'To confirm deletion type: "YES"' + ansiColors['grey']);
|
||||
|
||||
Sys.println(C_WHITE + 'To confirm deletion type: "YES"' + C_DEFAULT);
|
||||
|
||||
// Read user input
|
||||
var stdin = Sys.stdin();
|
||||
@ -102,19 +93,16 @@ class Main{
|
||||
if (strIn == "YES") {
|
||||
// Delete those fucking files
|
||||
deleteFiles(files);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
// Abort
|
||||
Sys.println('Aborting operation.');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static function usage():Void
|
||||
{
|
||||
static function usage():Void {
|
||||
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.");
|
||||
Sys.println("Safely runs rm -rf with a confirm prompt so you don't make an oopsie.");
|
||||
Sys.println("");
|
||||
Sys.println("Available OPTIONS:");
|
||||
for (key in switches.keys()) {
|
||||
@ -123,15 +111,13 @@ class Main{
|
||||
// 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
|
||||
{
|
||||
|
||||
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');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user