RiverGlide/CukeSalad

View on GitHub
bin/cukesalad

Summary

Maintainability
Test Coverage
#!/usr/bin/env ruby
require 'optparse'
require 'cukesalad/cli'
CONFIRMATION = 'y'

OptionParser.new do |opts|
  opts.banner = "Usage: cukesalad or cukesalad project"

  begin
    opts.parse!(ARGV)
  rescue OptionParser::ParseError => e
    warn e.message
    puts opts
    exit 1
  end
end

def user_confirm_setup? project
  puts %Q|About to set-up project '#{project}' and configure cukesalad
The following project structure will be created:
  #{project}
  #{project}/features
  #{project}/features/tasks
  #{project}/features/roles
  #{project}/features/support
  #{project}/features/support/env.rb
Continue (y/n)?|
user_confirmed?
end

def user_confirm_configuration?
  puts %Q|About to set-up your current project to work with cukesalad
The following files will be created/modified:
    features
    features/tasks
    features/roles
    features/support
    features/support/env.rb
 Continue (y/n)?|
 user_confirmed?
end

def user_confirmed?
  STDIN.gets.chomp == CONFIRMATION
end

if ARGV.empty?
  if user_confirm_configuration?
    CukeSalad::CLI.configure_existing_project
  else
    abort "User aborted"
  end
elsif ARGV.first
  project = ARGV[0]
  if user_confirm_setup? project
    CukeSalad::CLI.create_new_project project
  else
    abort "User aborted"
  end
end