svenfuchs/cl

View on GitHub
examples/readme/format

Summary

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

require 'cl'

class Add < Cl::Cmd
  register :add

  opt '--to GROUP', format: /^\w+$/

  def run
    p to: to
  end
end

Cl.new('owners').run(%w(add --to one))

# Output:
#
#   {:to=>"one"}

Cl.new('owners').run(['add', '--to', 'does not match!'])

# Output:
#
#   Invalid format: to (format: /^\w+$/)
#
#   Usage: owners add [options]
#
#   Options:
#
#     --to GROUP      type: string, format: /^\w+$/
#     --help          Get help on this command