Sha256: e0e5dea0f38665ba9b5d8e0074f395a27b8472b2d127aa971a6e27effdfd20d1

Contents?: true

Size: 1002 Bytes

Versions: 13

Compression:

Stored size: 1002 Bytes

Contents

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

require 'cl'

class Required < Cl::Cmd
  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: true
#     two         type: string
#
#   Options:
#
#     --help      Get help on this command

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

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

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
cl-1.2.0 examples/args/required
cl-1.1.5 examples/args/required
cl-1.1.4 examples/args/required
cl-1.1.3 examples/args/required
cl-1.1.2 examples/args/required
cl-1.1.1 examples/args/required
cl-1.1.0 examples/args/required
cl-1.0.5 examples/args/required
cl-1.0.4 examples/args/required
cl-1.0.3 examples/args/required
cl-1.0.2 examples/args/required
cl-1.0.1 examples/args/required
cl-1.0.0 examples/args/required