diff --git a/Makefile b/Makefile index a41e31c..32a5b8b 100644 --- a/Makefile +++ b/Makefile @@ -3,11 +3,6 @@ build: v -o flist . sudo ./flist install -build-win: - v fmt -w flist.v - v -o flist . - ./flist.exe install - rebuild: sudo rm flist sudo flist uninstall @@ -17,4 +12,19 @@ rebuild: delete: sudo rm flist - sudo flist uninstall \ No newline at end of file + sudo flist uninstall + +build-win: + v fmt -w flist.v + v -o flist . + ./flist.exe install + +rebuild-win: + ./flist.exe uninstall + v fmt -w flist.v + v -o flist . + ./flist.exe install + +delete-win: + ./flist.exe uninstall + diff --git a/flist.v b/flist.v index d81f92d..2210e1f 100644 --- a/flist.v +++ b/flist.v @@ -57,12 +57,16 @@ fn remove_path_windows() { path_to_remove := r'C:\Program Files\flist' // Get the current PATH environment variable - mut current_path := os.getenv('PATH') + current_path := os.getenv('PATH') - // Remove the specified path from current PATH - paths := current_path.split(';') - updated_paths := paths.filter(it != path_to_remove) // Keep only paths that are not the one we want to remove - new_env_path := updated_paths.join(';') // Join the remaining paths back into a single string + // Check if the path_to_remove is in the current PATH + if !current_path.contains(path_to_remove) { + println('The directory is not in the PATH.') + return + } + + // Remove specified directory from the PATH + new_env_path := current_path.split(';').filter(it != path_to_remove).join(';') // Prepare the command to set the new PATH cmd := 'setx PATH "${new_env_path}"' @@ -135,15 +139,31 @@ fn install() { fn uninstall() { info_message('Uninstalling Flist CLI...') + if os.exists(binary_location) { + // Remove the binary file os.rm(binary_location) or { panic(err) } success_message('Flist CLI has been removed from ' + binary_location) + + // Get the directory of the binary + parent_dir := os.dir(binary_location) + + // Check if the parent directory is empty + if os.is_dir_empty(parent_dir) { + // Remove the parent directory + os.rmdir(parent_dir) or { panic(err) } + success_message('The directory ' + parent_dir + ' has been removed as it is empty.') + } else { + info_message('The directory ' + parent_dir + ' is not empty, so it was not removed.') + } } else { info_message('Flist CLI is not installed at ' + binary_location) } - // if os.user_os() == 'windows' { - // remove_path_windows() - // } + + // Uncomment the following block if you want to remove from PATH for Windows. + // if os.user_os() == 'windows' { + // remove_path_windows() + // } } fn login() {