forked from AtelierArith/OkinawaCompPhysFoodSurvey2024.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interactive.jl
49 lines (40 loc) · 1.47 KB
/
interactive.jl
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
48
49
using LibGit2
using REPL.TerminalMenus
using TOML
using OkinawaCompPhysFoodSurvey2024: INTERACTIVE_OKINAWA_FOOD_OPTIONS
default_githubuser() = LibGit2.getconfig("github.user", "")
struct MissingUserException <: Exception end
function Base.showerror(io::IO, ::MissingUserException)
s = """Git hosting service username is required, set one with keyword `githubuser="<YourGitHubUserName>"`"""
print(io, s)
end
function interactive(; githubuser::Union{String,Nothing}=nothing)
if isnothing(githubuser)
githubuser = default_githubuser()::String
end
@info "githubuser=$githubuser"
!isempty(githubuser) || throw(MissingUserException())
try
menu = RadioMenu(INTERACTIVE_OKINAWA_FOOD_OPTIONS, pagesize=4)
choice = request("Choose your favorite okinawa food:", menu)
if choice != -1
println("Your favorite food is ", INTERACTIVE_OKINAWA_FOOD_OPTIONS[choice], "!")
else
println("Menu canceled.")
end
userworkspace = joinpath("poll", githubuser, "food")
mkpath(userworkspace)
tomlfile = joinpath(userworkspace, "Data.toml")
food = INTERACTIVE_OKINAWA_FOOD_OPTIONS[choice]
open(tomlfile, "w") do io
TOML.print(io, Dict(:food => String[food]))
end
@info "tomlfile=$tomlfile has been created"
catch e
e isa InterruptException || rethrow()
println()
@info "Cancelled"
return nothing
end
end
interactive()