-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyon.lua
47 lines (38 loc) · 839 Bytes
/
yon.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function valexit(val)
if string.lower(val) == "y" then
os.exit(0)
else
os.exit(1)
end
end
function main()
local opts = {}
if #arg == 0 then
arg = {"y", "N"}
end
io.write("Pick one: " .. (table.concat(arg, '/')) .. ' ')
local picker = string.lower(io.read(1))
local default = nil
for ii, word in ipairs(arg) do
local key = string.lower(string.sub(word, 1, 1))
if picker == key then
valexit(word)
end
-- this is a weird way of checking for capitals
if not default and key ~= string.sub(word, 1, 1) then
default = word
end
end
if picker == '\n' then
if default then
valexit(default)
else
print("No default set, try again")
main()
end
else
io.stderr:write("Unknown choice: " .. picker .. "\n")
os.exit(1)
end
end
main()