#!/usr/bin/env ruby require 'colorized_string' require 'gli' require_relative '../lib/howitzer/version' # Howitzer Command line interface module HowitzerCli extend GLI::App synopsis_format :compact program_desc 'Ruby based framework for acceptance testing' version Howitzer::VERSION desc 'Generate new project' arg_name '' command :new do |c| c.desc 'Integrate Cucumber' c.switch %i[c cucumber], negatable: false c.desc 'Integrate Rspec' c.switch %i[r rspec], negatable: false c.desc 'Integrate Turnip' c.switch %i[t turnip], negatable: false c.action do |_global_options, options, args| if !args.empty? validate_options(options) load_generators path_to_dir = File.join(Dir.pwd, args.first) puts ColorizedString.new(' * New project directory creation ...').light_cyan Dir.mkdir(path_to_dir) puts " #{ColorizedString.new('Created').light_green} './#{args.first}' folder" Dir.chdir(path_to_dir) Howitzer::ConfigGenerator.new(options) Howitzer::WebGenerator.new(options) Howitzer::TasksGenerator.new(options) Howitzer::EmailsGenerator.new(options) Howitzer::RootGenerator.new(options) Howitzer::PrerequisitesGenerator.new(options) if options[:cucumber] Howitzer::CucumberGenerator.new(options) elsif options[:rspec] Howitzer::RspecGenerator.new(options) elsif options['turnip'] Howitzer::TurnipGenerator.new(options) end puts ColorizedString.new('[WARN] Extra parameters were skipped').yellow if args.size > 1 elsif args.size.zero? exit_now!(ColorizedString.new('Please specify ').red, 64) end end end desc 'Upgrade existing project' command :update do |c| c.action do check_project_presence load_generators Howitzer::ConfigGenerator.new Howitzer::WebGenerator.new Howitzer::TasksGenerator.new Howitzer::EmailsGenerator.new Howitzer::PrerequisitesGenerator.new if cucumber_integrated? Howitzer::RootGenerator.new(cucumber: true) Howitzer::CucumberGenerator.new elsif rspec_integrated? Howitzer::RootGenerator.new(rspec: true) Howitzer::RspecGenerator.new elsif turnip_integrated? Howitzer::RootGenerator.new(turnip: true) Howitzer::TurnipGenerator.new end end end # helpers class << self private def validate_options(options) return if [options[:cucumber], options[:rspec], options[:turnip]].count { |el| el } == 1 exit_now!(ColorizedString.new('Provide --cucumber, --rspec or --turnip option').red, 64) end def check_project_presence exit_now!(ColorizedString.new('Current directory is not Howitzer project').red, 126) unless howitzer_project? end def howitzer_project? (Dir.exist?('web') || Dir.exist?('pages')) && Dir.exist?('config') end def load_generators Dir[ File.join(__dir__, '..', 'generators', '**', '*_generator.rb') ].each { |f| require File.expand_path(f) } end def cucumber_integrated? Dir.exist?('features') end def rspec_integrated? File.exist?('spec/spec_helper.rb') && !File.exist?('spec/turnip_helper.rb') end def turnip_integrated? File.exist?('spec/spec_helper.rb') && File.exist?('spec/turnip_helper.rb') end end end exit(HowitzerCli.run(ARGV)) unless ENV['TEST_MODE']