Sha256: 8219c1ae385fb8e63a8c4b2ae7510f16c93086a1e4c01aa244ed24f7ae8a9fca

Contents?: true

Size: 1.39 KB

Versions: 3

Compression:

Stored size: 1.39 KB

Contents

require File.expand_path("../lib/cutest", File.dirname(__FILE__))

if ARGV.empty?
  puts "usage: cutest [-r lib] [-v] 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.2"

    attr :argv
    attr :opts

    def self.run(args, opts)
      new(args, opts).run
    end

    def initialize(argv, opts)
      @argv = argv.dup
      @opts = opts
    end

    def run
      args = []

      while argv.any?

        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.
          flag.call(*argv.shift(arity))
        else

          # Collect the items that don't correspond to
          # flags.
          args << item
        end
      end

      args
    end
  end
end

files = Cutest::Clap.run ARGV,
  "-r"      => lambda { |file| Cutest::REQUIREMENTS.push(file) },
  "-v"      => lambda { puts Cutest::VERSION }

case files.size
when 0 then exit
when 1 then Cutest.run_file(files.first) && puts
else        Cutest.run(Dir[*files])
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cutest-1.1.3 bin/cutest
cutest-1.1.2 bin/cutest
cutest-1.1.1 bin/cutest