I’m writing a config file parser using ConfParser for a config file which includes, among other things, the latitude, longitude, and networks from which clients may connect. The file looks like this:
Latitude 35.snip
Longitude -81.snip
ClientNet puma/24,puma/64
puma is the computer I’m running this on, and both IPv4 (192.168.1.0/24) and IPv6 netblocks are allowed to connect. Someone may have only one netblock that may connect. Here’s the code:
"""
getLatitude()
Gets the latitude from a configuration file. The latitude should be written
in degrees with decimals or degrees:minutes:seconds.
"""
function getLatitude()
ret=NaN
for c in confs()
str=retrieve(c,"Latitude")
try
ret=dms2rad(str)
catch
end
end
ret
end
"""
getLongitude()
Gets the longitude from a configuration file. The longitude should be written
in degrees with decimals or degrees:minutes:seconds.
"""
function getLongitude()
ret=NaN
for c in confs()
str=retrieve(c,"Longitude")
try
ret=dms2rad(str)
catch
end
end
ret
end
# snip parseNetblock(str::String) -> Vector{IPNet}
function getClientNet()
ret=IPNet[]
for c in confs()
str=retrieve(c,"ClientNet")
if str>""
nets=split(str,',')
for net in nets
try
append!(ret,parseNetblock(net))
catch
end
end
end
end
ret
end
This gave an error at if str>"" because str is not a String but a Vector{String}. So I tried retrieving the lines from the configuration. I got this:
julia> retrieve(EAConfig.confs()[1],"ClientNet")
2-element Vector{String}:
"puma/24"
"puma/64"
julia> retrieve(EAConfig.confs()[1],"Latitude")
"35.snip"
I then tried retrieve with a type argument:
julia> retrieve(EAConfig.confs()[1],"ClientNet",String)
ERROR: MethodError: no method matching parse(::Type{String}, ::Vector{String})
julia> retrieve(EAConfig.confs()[1],"Latitude",Vector{String})
ERROR: MethodError: no method matching parse(::Type{Vector{String}}, ::String)
How do I either get the string including the comma, or get a vector of strings, with only one string in the vector if there is no comma?
I’m going to temporarily have two ClientNet lines, but I’d rather have just one.