Sha256: c6097a021ab14c8df71ace54529032e2d77e35a53cc2a76d38a7275a89a9e493

Contents?: true

Size: 1.65 KB

Versions: 13

Compression:

Stored size: 1.65 KB

Contents

#!/usr/bin/env ruby
$: << File.expand_path('lib')

require 'cl'

module Cast
  class Bool < Cl::Cmd
    arg :bool, type: :bool

    def run
      p cmd: registry_key, bool: bool
    end
  end

  class Types < Cl::Cmd
    arg :a, type: :bool
    arg :b, type: :int
    arg :c, type: :float
    arg :d

    def run
      p cmd: registry_key, a: a, b: b, c: c, d: d
    end
  end
end

Cl.new($0).run(%w(bool on))

# Output:
#
#   {:cmd=>:bool, :bool=>true}

Cl.new($0).run(%w(types true 1 1.2 foo))

# Output:
#
#   {:cmd=>:types, :a=>true, :b=>1, :c=>1.2, :d=>"foo"}

Cl.new($0).run(%w(types true 1 1.2 foo bar))

# Output:
#
#   Too many arguments (given: 5, allowed: 4)
#
#   Usage: bin/examples types [a:bool] [b:int] [c:float] [d] [options]
#
#   Arguments:
#
#     a           type: bool
#     b           type: int
#     c           type: float
#     d           type: string
#
#   Options:
#
#     --help      Get help on this command

Cl.new($0).run(%w(types true one 1.2))

# Output:
#
#   Wrong argument type (given: "one", expected: int)
#
#   Usage: bin/examples types [a:bool] [b:int] [c:float] [d] [options]
#
#   Arguments:
#
#     a           type: bool
#     b           type: int
#     c           type: float
#     d           type: string
#
#   Options:
#
#     --help      Get help on this command

Cl.new($0).run(%w(types true 1 one))

# Output:
#
#   Wrong argument type (given: "one", expected: float)
#
#   Usage: bin/examples types [a:bool] [b:int] [c:float] [d] [options]
#
#   Arguments:
#
#     a           type: bool
#     b           type: int
#     c           type: float
#     d           type: string
#
#   Options:
#
#     --help      Get help on this command

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
cl-1.2.0 examples/args/cast
cl-1.1.5 examples/args/cast
cl-1.1.4 examples/args/cast
cl-1.1.3 examples/args/cast
cl-1.1.2 examples/args/cast
cl-1.1.1 examples/args/cast
cl-1.1.0 examples/args/cast
cl-1.0.5 examples/args/cast
cl-1.0.4 examples/args/cast
cl-1.0.3 examples/args/cast
cl-1.0.2 examples/args/cast
cl-1.0.1 examples/args/cast
cl-1.0.0 examples/args/cast