Sha256: bbb752557d3185fa47086201a31d19a2107f9288cd89bab9ad1f8a6bc0b120c7

Contents?: true

Size: 714 Bytes

Versions: 2

Compression:

Stored size: 714 Bytes

Contents

require 'cl'

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

  def run
    [self.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}"
end

output *Cl.run(*%w(required one two))
# Output:
# Called required with one="one" two="two"

output *Cl.run(*%w(required one))
# Output:
# Called required with one="one" two=nil

output *Cl.run(*%w(required))
# Output:
# Missing arguments (given: 0, required: 1)
#
# Usage: args.rb required one [two]

output *Cl.run(*%w(required one two three))
# Output:
# Too many arguments (given: 3, allowed: 2)
#
# Usage: args.rb required one [two]

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cl-0.0.4 examples/args/required.rb
cl-0.0.3 examples/args/required.rb