svenfuchs/cl

View on GitHub
examples/readme/enum

Summary

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

require 'cl'

class Add < Cl::Cmd
  register :add

  opt '--to GROUP', enum: %w(one two)

  def run
    p to: to
  end
end

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

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

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

# Output:
#
#   Unknown value: to=unknown (known values: one, two)
#
#   Usage: owners add [options]
#
#   Options:
#
#     --to GROUP      type: string, known values: one, two
#     --help          Get help on this command