Sha256: d9cb3d698ef3826def07702d3f661be0790d209c87870767cf6e968549a579c4
Contents?: true
Size: 744 Bytes
Versions: 13
Compression:
Stored size: 744 Bytes
Contents
require 'cl/cast' class Cl class Arg < Struct.new(:name, :opts) include Cast def define(const) const.send(:attr_accessor, name) end def set(cmd, value) cmd.send(:"#{name}=", cast(value)) end def type opts[:type] || :string end def description opts[:description] end def splat? type == :array end def required? !!opts[:required] end def to_s str = name case type when :array then str = "#{str}.." when :integer, :int then str = "#{str}:int" when :boolean, :bool then str = "#{str}:bool" when :float then str = "#{str}:float" end required? ? str : "[#{str}]" end end end
Version data entries
13 entries across 13 versions & 1 rubygems