Sha256: 34d421d5a84c5d78774d0ae2ebb2dc9f5b444630c0b412474ae390b7144eaeb4

Contents?: true

Size: 1 KB

Versions: 3

Compression:

Stored size: 1 KB

Contents

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

require 'cl'

class Required < Cl::Cmd
  register :required

  arg :one, required: true
  arg :two

  def run
    p cmd: registry_key, one: one, two: two
  end
end

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

# Output:
#
#   {:cmd=>:required, :one=>"one", :two=>"two"}

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

# Output:
#
#   {:cmd=>:required, :one=>"one", :two=>nil}

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

# Output:
#
#   Missing arguments (given: 0, required: 1)
#
#   Usage: bin/examples required one [two] [options]
#
#   Arguments:
#
#     one         type: string, required
#     two         type: string
#
#   Options:
#
#     --help      Get help on this command

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

# Output:
#
#   Too many arguments: one two three (given: 3, allowed: 2)
#
#   Usage: bin/examples required one [two] [options]
#
#   Arguments:
#
#     one         type: string, required
#     two         type: string
#
#   Options:
#
#     --help      Get help on this command

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
travis-cl-1.2.4 examples/args/required
cl-1.2.4 examples/args/required
cl-1.2.3 examples/args/required