made specific errors instead of general one

This commit is contained in:
Mik-TF 2024-10-12 06:22:15 -07:00
parent 25b609cba3
commit feea1941fe

24
flist.v
View File

@ -13,12 +13,6 @@ const binary_location = $if windows {
'/usr/local/bin/flist' '/usr/local/bin/flist'
} }
const err_privilege = $if windows {
'Run with admin PowerShell'
} $else {
'Run with sudo'
}
const docker_cmd = $if windows { const docker_cmd = $if windows {
'docker' 'docker'
} $else { } $else {
@ -146,15 +140,15 @@ fn install() {
current_exe := os.executable() current_exe := os.executable()
if os.exists(current_exe) { if os.exists(current_exe) {
os.mkdir_all(os.dir(binary_location)) or { os.mkdir_all(os.dir(binary_location)) or {
error_message('${err_privilege}: ${err}') error_message('Failed to create directory for binary: ${err}')
exit(1) exit(1)
} }
os.cp(current_exe, binary_location) or { os.cp(current_exe, binary_location) or {
error_message('${err_privilege}: ${err}') error_message('Failed to copy binary to path: ${err}')
exit(1) exit(1)
} }
os.chmod(binary_location, 0o755) or { os.chmod(binary_location, 0o755) or {
error_message('${err_privilege}: ${err}') error_message('Failed to change permissions to binary at path: ${err}')
exit(1) exit(1)
} }
$if windows { $if windows {
@ -174,7 +168,7 @@ fn uninstall() {
if os.exists(binary_location) { if os.exists(binary_location) {
// Remove the binary file // Remove the binary file
os.rm(binary_location) or { os.rm(binary_location) or {
error_message('${err_privilege}: ${err}') error_message('Failed to remove the binary at path: ${err}')
exit(1) exit(1)
} }
success_message('Flist CLI has been removed from ' + binary_location) success_message('Flist CLI has been removed from ' + binary_location)
@ -190,13 +184,13 @@ fn uninstall() {
fn login() { fn login() {
mut token_exists := os.exists(token_file) mut token_exists := os.exists(token_file)
os.mkdir_all(config_dir) or { os.mkdir_all(config_dir) or {
error_message('${err_privilege}: ${err}') error_message('Failed to create config folder for token and Docker username files: ${err}')
exit(1) exit(1)
} }
if !token_exists { if !token_exists {
tfhub_token := os.input('Please enter your TF Hub token: ') tfhub_token := os.input('Please enter your TF Hub token: ')
os.write_file(token_file, tfhub_token) or { os.write_file(token_file, tfhub_token) or {
error_message('${err_privilege}: ${err}') error_message('Failed to write TF Hub token to file: ${err}')
exit(1) exit(1)
} }
success_message('TF Hub token saved in ' + token_file) success_message('TF Hub token saved in ' + token_file)
@ -210,7 +204,7 @@ fn login() {
if !dockername_exists { if !dockername_exists {
docker_username = os.input('Please enter your Docker username: ') docker_username = os.input('Please enter your Docker username: ')
os.write_file(docker_username_file, docker_username) or { os.write_file(docker_username_file, docker_username) or {
error_message('${err_privilege}: ${err}') error_message('Failed to write Docker username to file: ${err}')
exit(1) exit(1)
} }
success_message('Docker username saved in ' + docker_username_file) success_message('Docker username saved in ' + docker_username_file)
@ -230,7 +224,7 @@ fn login() {
fn logout() { fn logout() {
if os.exists(token_file) { if os.exists(token_file) {
os.rm(token_file) or { os.rm(token_file) or {
error_message('${err_privilege}: ${err}') error_message('Failed to remove TF Hub token file at config directory: ${err}')
exit(1) exit(1)
} }
success_message('Your TF Hub token has been removed') success_message('Your TF Hub token has been removed')
@ -240,7 +234,7 @@ fn logout() {
if os.exists(docker_username_file) { if os.exists(docker_username_file) {
os.rm(docker_username_file) or { os.rm(docker_username_file) or {
error_message('${err_privilege}: ${err}') error_message('Failed to remove Docker username file in config folder: ${err}')
exit(1) exit(1)
} }
success_message('Your Docker username has been removed from the config folder.') success_message('Your Docker username has been removed from the config folder.')