Flist CLI Updated for Linux, MacOS, Windows #7
34
flist.v
34
flist.v
@ -5,6 +5,7 @@ import json
|
||||
import x.json2
|
||||
|
||||
const token_file = os.join_path(os.home_dir(), '.config', 'tfhubtoken')
|
||||
const token_dir = os.join_path(os.home_dir(), '.config')
|
||||
const binary_location = $if windows {
|
||||
'C:\\Program Files\\flist\\flist.exe'
|
||||
} $else {
|
||||
@ -105,17 +106,17 @@ fn create_box(content []string, padding int) string {
|
||||
max_width += padding * 2
|
||||
|
||||
separator := '━'.repeat(max_width + 2) // +2 for left and right borders
|
||||
mut box_content := term.blue('┏${separator}┓') + '\n'
|
||||
mut box_content := term.cyan('┏${separator}┓') + '\n'
|
||||
|
||||
for line in content {
|
||||
clean_line := term.strip_ansi(line)
|
||||
padding_left := ' '.repeat(padding)
|
||||
padding_right := ' '.repeat(max_width - clean_line.len)
|
||||
box_content += term.blue('┃') + padding_left + line + padding_right + term.blue('┃') +
|
||||
box_content += term.cyan('┃') + padding_left + line + padding_right + term.cyan('┃') +
|
||||
'\n'
|
||||
}
|
||||
|
||||
box_content += term.blue('┗${separator}┛')
|
||||
box_content += term.cyan('┗${separator}┛')
|
||||
return box_content
|
||||
}
|
||||
|
||||
@ -170,6 +171,9 @@ fn login() {
|
||||
mut token_exists := os.exists(token_file)
|
||||
|
||||
if !token_exists {
|
||||
$if windows {
|
||||
os.mkdir_all(token_dir) or { panic(err) }
|
||||
}
|
||||
tfhub_token := os.input('Please enter your tfhub token: ')
|
||||
os.write_file(token_file, tfhub_token) or { panic(err) }
|
||||
success_message('Token saved in ' + token_file)
|
||||
@ -177,7 +181,7 @@ fn login() {
|
||||
info_message('Your Flist Hub token is already saved.')
|
||||
}
|
||||
|
||||
result := os.system('sudo docker login')
|
||||
result := $if windows { os.system('docker login') } $else { os.system('sudo docker login') }
|
||||
|
||||
if result == 0 {
|
||||
info_message('\nYou are already logged in to Docker.')
|
||||
@ -194,7 +198,7 @@ fn logout() {
|
||||
info_message('Your Flist Hub Token was already not present.')
|
||||
}
|
||||
|
||||
exit_code := os.system('sudo docker logout')
|
||||
exit_code := $if windows { os.system('docker logout') } $else { os.system('sudo docker logout') }
|
||||
if exit_code != 0 {
|
||||
error_message('Failed to log out from Docker Hub.')
|
||||
}
|
||||
@ -490,17 +494,17 @@ fn help() {
|
||||
|
||||
println('This tool turns Dockerfiles and Docker images directly into Flists on the TF Flist Hub, passing by the Docker Hub.\n')
|
||||
println(term.bold('Available commands:'))
|
||||
println(term.blue(' install ') + '- Install the Flist CLI')
|
||||
println(term.blue(' uninstall ') + '- Uninstall the Flist CLI')
|
||||
println(term.blue(' login ') + '- Log in to Docker Hub and save the Flist Hub token')
|
||||
println(term.blue(' logout ') + '- Log out of Docker Hub and remove the Flist Hub token')
|
||||
println(term.blue(' push ') +
|
||||
println(term.cyan(' install ') + '- Install the Flist CLI')
|
||||
println(term.cyan(' uninstall ') + '- Uninstall the Flist CLI')
|
||||
println(term.cyan(' login ') + '- Log in to Docker Hub and save the Flist Hub token')
|
||||
println(term.cyan(' logout ') + '- Log out of Docker Hub and remove the Flist Hub token')
|
||||
println(term.cyan(' push ') +
|
||||
'- Build and push a Docker image to Docker Hub, then convert and push it as an Flist to Flist Hub')
|
||||
println(term.blue(' delete ') + '- Delete an Flist from Flist Hub')
|
||||
println(term.blue(' rename ') + '- Rename an Flist in Flist Hub')
|
||||
println(term.blue(' ls ') + '- List all Flists of the current user')
|
||||
println(term.blue(' ls url ') + '- List all Flists of the current user with full URLs')
|
||||
println(term.blue(' help ') + '- Display this help message\n')
|
||||
println(term.cyan(' delete ') + '- Delete an Flist from Flist Hub')
|
||||
println(term.cyan(' rename ') + '- Rename an Flist in Flist Hub')
|
||||
println(term.cyan(' ls ') + '- List all Flists of the current user')
|
||||
println(term.cyan(' ls url ') + '- List all Flists of the current user with full URLs')
|
||||
println(term.cyan(' help ') + '- Display this help message\n')
|
||||
println(term.bold('Usage:'))
|
||||
println(term.yellow(' sudo ./flist install'))
|
||||
println(term.yellow(' sudo flist uninstall'))
|
||||
|
Loading…
Reference in New Issue
Block a user