#!/usr/bin/env ruby require 'rubygems' unless ENV['NO_RUBYGEMS'] Dir[File.join(File.dirname(__FILE__), '..', 'generators', '**', '*_generator.rb')].each{ |f| require File.expand_path(f) } def check_arguments expected_option_list = [ 'install --cucumber', 'install --rspec', 'install --cucumber --rspec', 'install --rspec --cucumber', '--version', '--help' ] actual_options = ARGV.map(&:downcase).join(' ') unless expected_option_list.include?(actual_options) puts "ERROR: incorrect options. Please, see help for details" show_help exit 1 end end def parse_options first_option = ARGV.shift.to_s.downcase case first_option when 'install' then execute_generator(ARGV.map(&:downcase)) when '--version' then show_version when '--help' then show_help else puts "ERROR: incorrect first argument ('#{first_option}')" show_help exit 1 end end private def show_help puts %{ howitzer [command {--cucumber, --rspec}] | {options} Commands are ... install Generate test framework units: --rspec add RSpec integration with framework --cucumber add Cucumber integration with framework Options are ... --help Display this help message. --version Display the program version. } end def show_version require_relative "../lib/howitzer/version" puts "Version: #{Howitzer::VERSION}" exit 0 end def execute_generator(options) if %w[--cucumber --rspec].include?(options.first) Howitzer::ConfigGenerator.new Howitzer::PagesGenerator.new Howitzer::TasksGenerator.new Howitzer::EmailsGenerator.new Howitzer::RootGenerator.new options.each do |option| case option when '--cucumber' then Howitzer::CucumberGenerator.new when '--rspec' then Howitzer::RspecGenerator.new else nil end end else if options.empty? puts "ERROR: No option specified for install command." else puts "ERROR: Unknown '#{options.first}' option specified." end show_help exit 1 end end unless ENV['TEST_MODE'] check_arguments parse_options end