Skip to content

Commit d522ec0

Browse files
committed
Specialized _converttype! for Nothing types
1 parent a8d2042 commit d522ec0

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/argsparsing.jl

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,12 @@ function _pop_count!(args::Vector{String}, flag::String)::Int
9696
return initial_arg_length - length(args)
9797
end
9898

99-
"""
100-
Convert string to Number type with parse or other type with direct conversion.
101-
Quit program if s is nothing or conversion fails.
102-
"""
103-
function _converttype!(::Type{T}, s::Union{String, Nothing}, name::String)::T where T
104-
if isnothing(s)
105-
_quit_try_help("Argument $name missing")
106-
end
107-
99+
"Convert string to Number type with parse or other type with direct conversion."
100+
function _converttype!(::Type{T}, s::String, name::String)::T where T
108101
try
109102
if T <: Number
110-
# Allow floating value to be passed to Int argument
111-
return T(parse(Float64, s))
103+
# Allow floating point value to be passed to Int argument
104+
return T(parse(Float64, s)::Float64)
112105
else
113106
return T(s)
114107
end
@@ -117,6 +110,11 @@ function _converttype!(::Type{T}, s::Union{String, Nothing}, name::String)::T wh
117110
end
118111
end
119112

113+
"Quit program if the value is nothing"
114+
function _converttype!(::Type{T}, ::Nothing, name::String)::Nothing where T
115+
_quit_try_help("Argument $name missing")
116+
end
117+
120118
"If x is not a string (i.e. literal passed as default) assume direct conversion is possible. Does NOT validate."
121119
function _converttype!(::Type{T}, x::Any, ::String)::T where T
122120
return T(x)

0 commit comments

Comments
 (0)