-
-
Save leejarvis/7623aa3b0cb22b9ce395 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$:.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