examples/args/splat
#!/usr/bin/env ruby
$: << File.expand_path('lib')
require 'cl'
module Splat
class Left < Cl::Cmd
register :left
arg :one, type: :array, splat: true
args :two, :three
def run
p cmd: registry_key, one: one, two: two, three: three
end
end
class Middle < Cl::Cmd
register :middle
arg :one
arg :two, type: :array, splat: true
arg :three
def run
p cmd: registry_key, one: one, two: two, three: three
end
end
class Right < Cl::Cmd
register :right
args :one, :two
arg :three, type: :array, splat: true
def run
p cmd: registry_key, one: one, two: two, three: three
end
end
end
Cl.new('splat').run(%w(left foo bar baz buz))
# Output:
#
# {:cmd=>:left, :one=>["foo", "bar"], :two=>"baz", :three=>"buz"}
Cl.new('splat').run(%w(middle foo bar baz buz))
# Output:
#
# {:cmd=>:middle, :one=>"foo", :two=>["bar", "baz"], :three=>"buz"}
Cl.new('splat').run(%w(right foo bar baz buz))
# Output:
#
# {:cmd=>:right, :one=>"foo", :two=>"bar", :three=>["baz", "buz"]}