svenfuchs/cl

View on GitHub
examples/readme/range

Summary

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

require 'cl'

class Add < Cl::Cmd
  register :add

  opt '--retries COUNT', type: :integer, min: 1, max: 5

  def run
    p retries: retries
  end
end

Cl.new('owners').run(%w(add --retries 1))

# Output:
#
#   {:retries=>1}

Cl.new('owners').run(%w(add --retries 10))

# Output:
#
#   Out of range: retries (min: 1, max: 5)
#
#   Usage: owners add [options]
#
#   Options:
#
#     --retries COUNT      type: integer, min: 1, max: 5
#     --help               Get help on this command