Make extra_versions accept any string, strip quotes from input (#185)

This commit is contained in:
Chris de Graaf 2020-06-04 11:59:18 -05:00 committed by GitHub
parent 1c8030be89
commit 25d4294c2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 4 deletions

View File

@ -105,7 +105,7 @@ end
function convert_input(P::Type, T::Type{<:Vector}, s::AbstractString) function convert_input(P::Type, T::Type{<:Vector}, s::AbstractString)
startswith(s, '[') && endswith(s, ']') && (s = s[2:end-1]) startswith(s, '[') && endswith(s, ']') && (s = s[2:end-1])
xs = map(strip, split(s, ",")) xs = map(x -> strip(x, [' ', '\t', '"']), split(s, ","))
return map(x -> convert_input(P, eltype(T), x), xs) return map(x -> convert_input(P, eltype(T), x), xs)
end end
@ -123,6 +123,7 @@ function prompt(P::Type, ::Type{T}, ::Val{name}, ::Nothing=nothing) where {T, na
default = defaultkw(P, name) default = defaultkw(P, name)
input = Base.prompt(pretty_message("Enter value for '$name' ($tips)")) input = Base.prompt(pretty_message("Enter value for '$name' ($tips)"))
input === nothing && throw(InterruptException()) input === nothing && throw(InterruptException())
input = strip(input, '"')
return if isempty(input) return if isempty(input)
default default
else else

View File

@ -392,7 +392,8 @@ Combine `t`'s Julia version with `versions`, and format them as `major.minor`.
This is useful for creating lists of versions to be included in CI configurations. This is useful for creating lists of versions to be included in CI configurations.
""" """
function collect_versions(t::Template, versions::Vector) function collect_versions(t::Template, versions::Vector)
vs = map(format_version, [t.julia, versions...]) custom = map(v -> v isa VersionNumber ? format_version(v) : string(v), versions)
vs = map(v -> lstrip(v, 'v'), [format_version(t.julia); custom])
return sort(unique(vs)) return sort(unique(vs))
end end
@ -408,4 +409,4 @@ is_ci(::Plugin) = false
is_ci(::AllCI) = true is_ci(::AllCI) = true
needs_username(::AllCI) = true needs_username(::AllCI) = true
customizable(::Type{<:AllCI}) = (:extra_versions => Vector{VersionNumber},) customizable(::Type{<:AllCI}) = (:extra_versions => Vector{String},)

View File

@ -157,7 +157,7 @@ end
@test PT.interactive(TravisCI) == TravisCI(; @test PT.interactive(TravisCI) == TravisCI(;
arm64=true, arm64=true,
coverage=false, coverage=false,
extra_versions=[v"1.1", v"1.2"], extra_versions=["1.1", "v1.2"],
file="x.txt", file="x.txt",
linux=true, linux=true,
osx=false, osx=false,
@ -183,6 +183,25 @@ end
@test PT.interactive(License) == License(; destination="COPYING", name="MIT") @test PT.interactive(License) == License(; destination="COPYING", name="MIT")
end end
@testset "Quotes" begin
print(
stdin.buffer,
CR, DOWN^2, CR, DONE, # Customize user and dir
"\"me\"", LF, # Enter user with quotes
"\"~\"", LF, # Enter home dir with quotes
)
@test Template(; interactive=true) == Template(; user="me", dir="~")
print(
stdin.buffer,
DOWN^2, CR, DONE, # Customize extra_versions
"\"1.1.1\", \"^1.5\", \"nightly\"", LF, # Enter versions with quotes
)
@test PT.interactive(TravisCI) == TravisCI(;
extra_versions=["1.1.1", "^1.5", "nightly"],
)
end
@testset "Union{T, Nothing} weirdness" begin @testset "Union{T, Nothing} weirdness" begin
print( print(
stdin.buffer, stdin.buffer,