Skip to content

Commit f30567e

Browse files
gbaraldigiordano
andauthored
[Wizard] Provide a way to to cancel the provision of URL for additional sources (#1100)
* Option to leave URL loop * Update src/wizard/obtain_source.jl * adding tests * Fix Tests * Remove deps Co-authored-by: Mosè Giordano <giordano@users.noreply.github.com>
1 parent 6fb9c12 commit f30567e

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

src/wizard/obtain_source.jl

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,12 @@ function download_source(state::WizardState)
9999
# First, ask the user where this is all coming from
100100
msg = replace(strip("""
101101
Please enter a URL (git repository or compressed archive) containing the
102-
source code to build:
102+
source code to build or `N` to stop:
103103
"""), "\n" => " ")
104104
new_entered_url = nonempty_line_prompt("URL", msg; ins=state.ins, outs=state.outs)
105-
105+
if new_entered_url == "N" || new_entered_url == "n"
106+
return new_entered_url, SetupSource(string(new_entered_url), "", "", "")
107+
end
106108
# Early-exit for invalid URLs, using HTTP.URIs.parse_uri() to ensure
107109
# it is a valid URL
108110
try
@@ -115,7 +117,6 @@ function download_source(state::WizardState)
115117
continue
116118
end
117119
end
118-
119120
# Did the user exit out with ^D or something else go horribly wrong?
120121
if entered_url === nothing
121122
error("Could not obtain source URL")
@@ -325,10 +326,16 @@ function obtain_source(state::WizardState)
325326

326327
while true
327328
url, file = download_source(state)
328-
push!(state.source_urls, url)
329-
push!(state.source_files, file)
330-
println(state.outs)
331-
329+
if url != "N"
330+
push!(state.source_urls, url)
331+
push!(state.source_files, file)
332+
println(state.outs)
333+
else
334+
if isempty(state.source_urls)
335+
printstyled(state.outs, "No URLs were given.\n", color=:yellow, bold=true)
336+
continue
337+
end
338+
end
332339
q = "Would you like to download additional sources? "
333340
if yn_prompt(state, q, :n) != :y
334341
break

test/wizard.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,30 @@ end
251251
@test length(state.dependencies) == 2
252252
@test any([BinaryBuilder.getname(d) == "ghr_jll" for d in state.dependencies])
253253
@test any([BinaryBuilder.getname(d) == "Zlib_jll" for d in state.dependencies])
254+
255+
# Test for escaping the URL prompt with N
256+
state = step2_state()
257+
with_wizard_output(state, Wizard.step2) do ins, outs
258+
call_response(ins, outs, "Please enter a URL", "http://127.0.0.1:$(port)/a/source.tar.gz")
259+
call_response(ins, outs, "Would you like to download additional sources", "Y")
260+
call_response(ins, outs, "Please enter a URL", "N")
261+
call_response(ins, outs, "Would you like to download additional sources", "N")
262+
call_response(ins, outs, "Do you require any (binary) dependencies", "N")
263+
call_response(ins, outs, "Enter a name for this project", "get_me_out")
264+
call_response(ins, outs, "Enter a version number", "1.0.0")
265+
call_response(ins, outs, "Do you want to customize the set of compilers?", "N")
266+
end
267+
@test state.source_urls == ["http://127.0.0.1:$(port)/a/source.tar.gz"]
268+
state = step2_state()
269+
with_wizard_output(state, Wizard.step2) do ins, outs
270+
call_response(ins, outs, "Please enter a URL", "N")
271+
call_response(ins, outs, "No URLs", "http://127.0.0.1:$(port)/a/source.tar.gz")
272+
call_response(ins, outs, "Would you like to download additional sources", "N")
273+
call_response(ins, outs, "Do you require any (binary) dependencies", "N")
274+
call_response(ins, outs, "Enter a name for this project", "no_urls")
275+
call_response(ins, outs, "Enter a version number", "1.0.0")
276+
call_response(ins, outs, "Do you want to customize the set of compilers?", "N")
277+
end
254278
end
255279

256280

0 commit comments

Comments
 (0)