Skip to content

Instantly share code, notes, and snippets.

@leejarvis

leejarvis/run.rb Secret

Created March 12, 2014 20:58
Show Gist options
  • Save leejarvis/7623aa3b0cb22b9ce395 to your computer and use it in GitHub Desktop.
Save leejarvis/7623aa3b0cb22b9ce395 to your computer and use it in GitHub Desktop.
$:.unshift './lib'
require 'slop'
opts = Slop.new do |o|
o.string :n, :name, 'Your name'
o.int :age, 'How old you is'
o.bool :verbose, 'Enable verbose mode', default: false
end
opts.parse
module Slop::Types
class ArrayType < Slop::Type
aliases :list
def initialize
@items = []
end
def call(value)
@items.concat value.split(delimiter, limit)
end
private
def delimiter
options[:delimiter] || ","
end
def limit
options[:limit] || 0
end
end
end
opts = Slop.parse %w(--people jon:james) do |o|
o.array :people, delimiter: ':'
end
opts[:people] #=> ['jon', 'james']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment