Sha256: cc012e9b01651ca376290a21b2739e9d939a4504644b4bb00601636e5f1de206

Contents?: true

Size: 816 Bytes

Versions: 29

Compression:

Stored size: 816 Bytes

Contents

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

require 'cl'

class Required < Cl::Cmd
  arg :one, required: true
  arg :two

  def run
    [registry_key, one: one, two: two]
  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(required one two))

# Output:
#
#   Called required with one="one" two="two"

output *Cl.new($0).run(%w(required one))

# Output:
#
#   Called required with one="one" two=nil

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

# Output:
#
#   Missing arguments (given: 0, required: 1)
#
#   Usage: args.rb required one [two]

output *Cl.new($0).run(%w(required one two three))

# Output:
#
#   Too many arguments (given: 3, allowed: 2)
#
#   Usage: args.rb required one [two]

Version data entries

29 entries across 29 versions & 1 rubygems

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