Re: tutorial// Ruby to Euphoria -- Example on Wiki
- Posted by _tom (admin) Jun 03, 2016
- 1803 views
petelomax said...
Some quick comments and ideas, ...
HTH, Pete
Thanks Pete, these are all good ideas that I should be using.
Version 2 of the Tux Installer
- starting to apply some of Pete's ideas
(1) The options sequence starts out as a LibreOffice spreadsheet and is saved as a .csv file.
"Help","h, --help","fedoraBased","rehelBased","debianBased","archLinux","voidLinux","sabayon" "Show Current Version","-v, --version","dnf","yum","apt-get","pacman","xbps-install","equo" "Install","i, -i, add, get, -S, install","dnf install","yum install","apt install","packman -S","xbps-install","equo i" "Reinstall","ri, -ri, reinstall","dnf reinstall","yum reinstall","apt install –reinstall","packman -S --force","xbps-install -f","equo i" "Search","s, -s, se, -Ss, search, find","dnf search","yum search","apt search","packman -Ss","xbps-query -Rs","equo s" "Update","u, up, -u, -Su, upgrade","dnf upgrade","yum update","apt upgrade","packman -Su","xbps-install -u","equo u" "Sync","sy, -Sy, sync, refresh ","dnf --refresh check-update","yum check-update","apt update","packman -Sy","xbps-install -S","equo up" "Sync and Update","su, -Syu, sup, syncup","dnf --refresh upgrade","yum check-update; yum update","apt update; sudo apt upgrade","packman -Syu","xbps-install -Su ","equo up && sudo equo u" "Remove","r, -R, rm, remove, delete","dnf install","yum remove","apt remove","packman -R","xbps-remove","equo rm" "Recursive Remove","-rf. -Rdd, force-remove","dnf install","yum remove","apt remove –purge","packman -Rdd","xbps-remove -f","equo rm –norecursive" "Check Updates","su, -Syu, sup, syncup","dnf check-update","yum check-update"," ","packman checkupdates"," "," " "Clean","c, -c, clean","dnf autoremove","yum autoremove","apt autoremove","packman -Rsn $(packman -Qdtq)","xbps-remove -O","equo cleanup"
Edit this file to add more file managers and adjust the options arguments.
Putting everything into one file should solve the brittle aspect of version one.
(2)
Launch this utility to convert the .csv to a Euphoria include file:
include std/io.e sequence raw = read_lines( "options.csv" ) for line=1 to length(raw) do raw[line] = "{ " & raw[line] & "}," end for raw = prepend(raw, "export sequence options = {" ) raw = append(raw, "$}" ) write_lines( "options.e", raw ) printf(1, "done" )
(3)
Launch main.ex to test the program:
include std/filesys.e include options.e clear_screen() procedure version() if equal(mgr_index, 0) then printf(1, "Can not identify your package manager.\n" ) else printf(1, "\nYou have the %s package manager installed.\n", {mgr_name} ) end if printf(1, "This is euTux 1.0\nplease see orignal Tux (c) by silverstone" ) end procedure procedure usage() integer HELP_MSG = 1, HELP_LIST = 2 printf(1, "Usage : tux [options] [arguments]\n\n" ) for arg=1 to length(options) do printf(1, "%30s : %s\n", { options[arg][HELP_MSG], options[arg][HELP_LIST] } ) end for version() end procedure -- identify installed package manager sequence mgr_list = options[2] -- managers are listed in line two sequence mgr_name = "" integer mgr_index = 0 for mgr = 3 to length(mgr_list) do sequence pkmgr = locate_file( mgr_list[mgr] ) if file_type( pkmgr ) = FILETYPE_FILE then mgr_index = mgr mgr_name = options[2][mgr_index] exit end if end for sequence cmd = command_line() integer cmd_count = length(cmd) if cmd_count < 3 then usage() elsif cmd_count = 3 then if find( cmd[3], { "h", "--help" } ) then usage() end if if find( cmd[3], { "v", "--version" } ) then version() end if elsif cmd_count = 4 then for i = 1 to length(options) do if match( cmd[3], options[i][2] ) then sequence action = options[i][mgr_index] & " " & cmd[4] system( action ) exit end if end for end if printf(1, "\n\ndone" )
(4) Compile with euc.
I tend to develop programs by removing code until the program works.
_tom