From ca543c10b7cc44641584add562001e767f3046e7 Mon Sep 17 00:00:00 2001 From: Mik-TF Date: Wed, 9 Oct 2024 15:26:18 -0700 Subject: [PATCH] started work on install windows --- .gitignore | 3 ++- flist.v | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 405becf..0ef9f17 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ flist -flist.exe \ No newline at end of file +flist.exe +test/ \ No newline at end of file diff --git a/flist.v b/flist.v index 66076e8..d81f92d 100644 --- a/flist.v +++ b/flist.v @@ -23,6 +23,60 @@ struct Response { payload Payload } +fn add_path_windows() { + // Define the new directory path to add + new_path := r'C:\Program Files\flist' + + // Get the current PATH environment variable + current_path := os.getenv('PATH') + + // Check if the new_path is already in the current PATH + if current_path.contains(new_path) { + println('The directory is already in the PATH.') + return + } + + // Construct the new PATH by appending the new_path + new_env_path := '${current_path};${new_path}' + + // Prepare the command to set the new PATH + cmd := 'setx PATH "${new_env_path}"' + + // Execute the command to update the PATH + exit_code := os.system(cmd.replace('"$', '${new_env_path}"')) + + if exit_code == 0 { + println('PATH updated successfully.') + } else { + println('Failed to update the PATH. Please try running the script as an administrator.') + } +} + +fn remove_path_windows() { + // Define the directory path to remove + path_to_remove := r'C:\Program Files\flist' + + // Get the current PATH environment variable + mut 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 + + // Prepare the command to set the new PATH + cmd := 'setx PATH "${new_env_path}"' + + // Execute the command to update the PATH + exit_code := os.system(cmd.replace('"$', '${new_env_path}"')) + + if exit_code == 0 { + println('PATH updated successfully.') + } else { + println('Failed to update the PATH. Please try running the script as an administrator.') + } +} + fn error_message(msg string) { println(term.red('\nError: ') + msg) println(term.yellow("Run 'flist help' for usage information.\n")) @@ -68,6 +122,9 @@ fn install() { os.mkdir_all(os.dir(binary_location)) or { panic(err) } os.cp(current_exe, binary_location) or { panic(err) } os.chmod(binary_location, 0o755) or { panic(err) } + if os.user_os() == 'windows' { + add_path_windows() + } success_message('Flist CLI has been installed to ' + binary_location) info_message("You can now use it by running 'flist help'") } else { @@ -84,6 +141,9 @@ fn uninstall() { } else { info_message('Flist CLI is not installed at ' + binary_location) } + // if os.user_os() == 'windows' { + // remove_path_windows() + // } } fn login() {