Skip to content

Instantly share code, notes, and snippets.

@trans
Created September 21, 2015 03:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trans/4ea36a45477129a92931 to your computer and use it in GitHub Desktop.
Save trans/4ea36a45477129a92931 to your computer and use it in GitHub Desktop.
$argv = [] of String
def cli(argv=ARGV)
# Convert single dash flags into multiple flags.
a = [] of String
argv.each do |v|
if v[0,1] == "-" && v[1,1] != "-"
a.concat(v[1..-1].chars.map{|c| "-#{c}"})
else
a << v
end
end
$argv = a
yield
end
def opt(flags : String, &proc : -> _)
#flags.split(/\s+/).each do |flag|
i = $argv.index(flags)
if i
$argv.delete(i)
proc.call()
end
#end
$argv
end
def opt(flags : String, &proc : String -> _)
#flags.split(/\s+/).each do |flag|
i = $argv.index(flags)
if i
$argv.delete(i)
if proc.arity == 1
arg = $argv.delete(i+1)
proc.call(arg)
else
proc.call
end
end
#end
$argv
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment