Sha256: e9bb12bd6743e9af075c4ee646f83991108e2538f41b62680d6179da8a66de67

Contents?: true

Size: 1.12 KB

Versions: 29

Compression:

Stored size: 1.12 KB

Contents

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

require 'cl'

class SplatLeft < Cl::Cmd
  register 'splat:left'

  arg :one, type: :array
  args :two, :three

  def run
    [registry_key, one: one, two: two, three: three]
  end
end

class SplatMiddle < Cl::Cmd
  register 'splat:middle'

  arg :one
  arg :two, type: :array
  arg :three

  def run
    [registry_key, one: one, two: two, three: three]
  end
end

class SplatRight < Cl::Cmd
  register 'splat:right'

  args :one, :two
  arg :three, type: :array

  def run
    [registry_key, one: one, two: two, three: three]
  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(splat left foo bar baz buz))

# Output:
#
#   Called splat:left with one=["foo", "bar"] two="baz" three="buz"

output *Cl.new($0).run(%w(splat middle foo bar baz buz))

# Output:
#
#   Called splat:middle with one="foo" two=["bar", "baz"] three="buz"

output *Cl.new($0).run(%w(splat right foo bar baz buz))

# Output:
#
#   Called splat:middle with one="foo" two="bar" three=["baz", "buz"]

Version data entries

29 entries across 29 versions & 1 rubygems

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