Sha256: eb000154989546f0582ffe20bbf27066e46e490c4ff16a87e4c88cbc492acd56

Contents?: true

Size: 804 Bytes

Versions: 28

Compression:

Stored size: 804 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 required?
      !!opts[:required]
    end

    def separator
      opts[:sep]
    end

    def splat?
      opts[:splat] && type == :array
    end

    def to_s
      str = name
      case type
      when :array          then str = "#{str}.."
      when :boolean, :bool then str = "#{str}:bool"
      when :integer, :int  then str = "#{str}:int"
      when :float          then str = "#{str}:float"
      end
      required? ? str : "[#{str}]"
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
cl-1.1.5 lib/cl/arg.rb
cl-1.1.4 lib/cl/arg.rb
cl-1.1.3 lib/cl/arg.rb
cl-1.1.2 lib/cl/arg.rb
cl-1.1.1 lib/cl/arg.rb
cl-1.1.0 lib/cl/arg.rb
cl-1.0.5 lib/cl/arg.rb
cl-1.0.4 lib/cl/arg.rb
cl-1.0.3 lib/cl/arg.rb
cl-1.0.2 lib/cl/arg.rb
cl-1.0.1 lib/cl/arg.rb
cl-1.0.0 lib/cl/arg.rb
cl-0.1.28 lib/cl/arg.rb
cl-0.1.27 lib/cl/arg.rb
cl-0.1.26 lib/cl/arg.rb
cl-0.1.25 lib/cl/arg.rb
cl-0.1.24 lib/cl/arg.rb
cl-0.1.23 lib/cl/arg.rb
cl-0.1.22 lib/cl/arg.rb
cl-0.1.21 lib/cl/arg.rb