svenfuchs/cl

View on GitHub
examples/readme/requires

Summary

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

class Add < Cl::Cmd
  register :add

  opt '--to GROUP'
  opt '--other GROUP', requires: :to

  def run
    p to: to, other: other
  end
end

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

# Output:
#
#   {:to=>"one", :other=>"two"}

Cl.new('owners').run(%w(add --other two))

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