Sha256: 26b6f875043f0f3fed1153d33eeb9571edb919ca0f88586a98cf0880fd63dcb7

Contents?: true

Size: 1.37 KB

Versions: 29

Compression:

Stored size: 1.37 KB

Contents

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

require 'cl'

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

  def run
    [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
    [registry_key, a: a, b: b, c: c, d: d]
  end
end

def output(cmd, args)
  args = args.map { |key, value| "#{key}=#{value.inspect}" }.join(' ')
  puts "Called #{cmd} with #{args}\n\n"
end

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

# Output:
#
#   Called bool with bool=true

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

# Output:
#
#   Called bool with bool=true

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

# Output:
#
#   Called bool with bool=true

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

# Output:
#
#   Called bool with bool=true

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

# Output:
#
#   Called types with a=true b=1 c=1.2 d="foo"

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

# Output:
#
#   Too many arguments (given: 5, allowed: 4)
#
#   Usage: cast.rb types [a (bool)] [b (int)] [c (float)] [d]

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

# Output:
#
#   Wrong argument type (given: "one", expected: int)
#
#   Usage: cast.rb types [a (bool)] [b (int)] [c (float)] [d]

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

# Output:
#
#   Wrong argument type (given: "one", expected: float)
#
#   Usage: cast.rb types [a (bool)] [b (int)] [c (float)] [d]

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
cl-0.1.28 examples/args/cast
cl-0.1.27 examples/args/cast
cl-0.1.26 examples/args/cast
cl-0.1.25 examples/args/cast
cl-0.1.24 examples/args/cast
cl-0.1.23 examples/args/cast
cl-0.1.22 examples/args/cast
cl-0.1.21 examples/args/cast
cl-0.1.20 examples/args/cast
cl-0.1.19 examples/args/cast
cl-0.1.18 examples/args/cast
cl-0.1.17 examples/args/cast
cl-0.1.16 examples/args/cast
cl-0.1.15 examples/args/cast
cl-0.1.14 examples/args/cast
cl-0.1.13 examples/args/cast
cl-0.1.12 examples/args/cast
cl-0.1.11 examples/args/cast
cl-0.1.10 examples/args/cast
cl-0.1.9 examples/args/cast