svenfuchs/cl

View on GitHub
examples/readme/required

Summary

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

require 'cl'

class Add < Cl::Cmd
  register :add

  opt '--to GROUP', required: true

  def run
    p to: to
  end
end

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

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

Cl.new('owners').run(%w(add))

# Output:
#
#   Missing required option: to
#
#   Usage: owners add [options]
#
#   Options:
#
#     --to GROUP      type: string, required
#     --help          Get help on this command