bin/cutest in cutest-1.0.0.beta vs bin/cutest in cutest-1.0.0.beta1
- old
+ new
@@ -1,45 +1,56 @@
#! /usr/bin/env ruby -rubygems
require File.expand_path("../lib/cutest", File.dirname(__FILE__))
if ARGV.empty?
- puts "usage: cutest [-r lib] [-v] file ..."
+ puts "usage: cutest [-r lib] [-v] [--debug] file ..."
exit
end
class Cutest
# Clap: Command line argument parsing.
# http://github.com/soveran/clap
# http://rubygems.org/gems/clap
class Clap
- VERSION = "0.0.1"
+ VERSION = "0.0.2"
attr :argv
attr :opts
def self.run(args, opts)
new(args, opts).run
end
def initialize(argv, opts)
- @argv = argv.reverse.dup
+ @argv = argv.dup
@opts = opts
end
def run
args = []
while argv.any?
- item = argv.pop
- if opts[item]
+ item = argv.shift
+ flag = opts[item]
+ if flag
+
+ # Work around lambda semantics in 1.8.7.
+ arity = [flag.arity, 0].max
+
+ # Raise if there are not enough parameters
+ # available for the flag.
+ if argv.size < arity
+ raise ArgumentError
+ end
+
# Call the lambda with N items from argv,
# where N is the lambda's arity.
- opts[item].call(*argv.pop(opts[item].arity))
+ flag.call(*argv.shift(arity))
else
# Collect the items that don't correspond to
# flags.
args << item
@@ -50,9 +61,10 @@
end
end
end
files = Cutest::Clap.run ARGV,
- "-r" => lambda { |file| require file },
- "-v" => lambda { puts Cutest::VERSION }
+ "-r" => lambda { |file| require file },
+ "-v" => lambda { puts Cutest::VERSION },
+ "--debug" => lambda { ENV["DEBUG"] = true }
Cutest.run(Dir[*files]) if files.any?