Had to fix some things in coerce
This commit is contained in:
+27
-4
@@ -241,23 +241,46 @@ module CliGen
|
||||
when "f","false","0"
|
||||
false
|
||||
else
|
||||
raise "ERROR"
|
||||
abort "ERROR : Flag({{T}}, long: #{@long_key}) : #{raw} is not a valid boolean identifier"
|
||||
end
|
||||
{% elsif T == Int32 %}
|
||||
raw.to_i
|
||||
{% elsif T == Time %}
|
||||
parse_time(raw)
|
||||
{% elsif T <= Array %}
|
||||
if raw.includes?(@delimiter)
|
||||
{% elem = T.type_vars.first %}
|
||||
raw.split(@delimiter).map do |val|
|
||||
unless @format.nil?
|
||||
abort "ERROR : Flag({{T}}, long: #{@long_key}) : #{val} does not match a valid format" unless val =~ @format
|
||||
end
|
||||
|
||||
{% if elem == Int32 %}
|
||||
raw.split(@delimiter).map(&.to_i)
|
||||
abort "ERROR : Flag({{T}}, long: #{@long_key}) : #{val} is not an integer" unless val =~ /^[[:digit:]]+$/
|
||||
val.to_i
|
||||
{% elsif elem == String %}
|
||||
raw.split(@delimiter)
|
||||
val
|
||||
{% elsif elem.class < CliGen::Coercable %}
|
||||
raw.split(@delimiter).map{|i| {{elem}}.coerce(i)}
|
||||
{{elem}}.coerce(val)
|
||||
{% else %}
|
||||
{% raise "ERROR : Flag(#{T}) : #{elem} is not a coercable type. If you wish to coerce it from a bare string extend CliGen::Coercable & implement the class method" %}
|
||||
{% end %}
|
||||
end
|
||||
else
|
||||
unless @format.nil?
|
||||
abort "ERROR : Flag({{T}}, long: #{@long_key}) : #{raw} does not match a valid format" unless raw =~ @format
|
||||
end
|
||||
{% if elem == Int32 %}
|
||||
abort "ERROR : Flag({{T}}, long: #{@long_key}) : #{raw} is not an integer" unless raw =~ /^[[:digit:]]+$/
|
||||
[ raw.to_i ]
|
||||
{% elsif elem == String %}
|
||||
[ raw ]
|
||||
{% elsif elem.class < CliGen::Coercable %}
|
||||
[ {{elem}}.coerce(raw) ]
|
||||
{% else %}
|
||||
{% raise "ERROR : Flag(#{T}) : #{T} is not a coercable type. If you wish to coerce it from a bare string extend CliGen::Coercable & implement the class method" %}
|
||||
{% end %}
|
||||
end
|
||||
{% elsif T == String %} # String
|
||||
raw
|
||||
{% elsif T.class < CliGen::Coercable %}
|
||||
|
||||
Reference in New Issue
Block a user