Had to fix some things in coerce
This commit is contained in:
+33
-10
@@ -248,16 +248,39 @@ module CliGen
|
|||||||
{% elsif T == Time %}
|
{% elsif T == Time %}
|
||||||
parse_time(raw)
|
parse_time(raw)
|
||||||
{% elsif T <= Array %}
|
{% elsif T <= Array %}
|
||||||
{% elem = T.type_vars.first %}
|
if raw.includes?(@delimiter)
|
||||||
{% if elem == Int32 %}
|
{% elem = T.type_vars.first %}
|
||||||
raw.split(@delimiter).map(&.to_i)
|
raw.split(@delimiter).map do |val|
|
||||||
{% elsif elem == String %}
|
unless @format.nil?
|
||||||
raw.split(@delimiter)
|
abort "ERROR : Flag({{T}}, long: #{@long_key}) : #{val} does not match a valid format" unless val =~ @format
|
||||||
{% elsif elem.class < CliGen::Coercable %}
|
end
|
||||||
raw.split(@delimiter).map{|i| {{elem}}.coerce(i)}
|
|
||||||
{% else %}
|
{% if elem == Int32 %}
|
||||||
{% 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" %}
|
abort "ERROR : Flag({{T}}, long: #{@long_key}) : #{val} is not an integer" unless val =~ /^[[:digit:]]+$/
|
||||||
{% end %}
|
val.to_i
|
||||||
|
{% elsif elem == String %}
|
||||||
|
val
|
||||||
|
{% elsif elem.class < CliGen::Coercable %}
|
||||||
|
{{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
|
{% elsif T == String %} # String
|
||||||
raw
|
raw
|
||||||
{% elsif T.class < CliGen::Coercable %}
|
{% elsif T.class < CliGen::Coercable %}
|
||||||
|
|||||||
Reference in New Issue
Block a user