Had to fix some things in coerce

This commit is contained in:
Tristan Ancelet
2026-08-14 15:32:44 -05:00
parent 09389cb5e9
commit 6535753fa3
+34 -11
View File
@@ -241,23 +241,46 @@ module CliGen
when "f","false","0" when "f","false","0"
false false
else else
raise "ERROR" abort "ERROR : Flag({{T}}, long: #{@long_key}) : #{raw} is not a valid boolean identifier"
end end
{% elsif T == Int32 %} {% elsif T == Int32 %}
raw.to_i raw.to_i
{% 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 %}