Atalanta/leibniz

View on GitHub
bin/leibniz

Summary

Maintainability
Test Coverage
#!/usr/bin/env ruby

$:.unshift File.join(File.dirname(__FILE__), %w{.. lib})
require 'thor'
require 'leibniz'
require 'pathname'

# Trap interrupts to quit cleanly. See
# https://twitter.com/mitchellh/status/283014103189053442
Signal.trap("INT") { exit 1 }

class LeibnizCli < Thor
  include Thor::Actions

  desc 'init', 'Set up a project ready for Leibniz Acceptance Testing'
  option :driver, :default => 'vagrant'
  def init
    set_template_root
    create_leibniz_yaml(options[:driver])
    create_skeleton_feature
    append_to_gitignore(".leibniz/")
    append_to_gitignore(".kitchen/")
  end
  
  desc "version", "Print Leibniz's version information"
    def version
      say "Leibniz version #{Leibniz::VERSION}"
    end
    map %w(-v --version) => :version

    private

    def set_template_root
      LeibnizCli.source_root Pathname.new(File.expand_path('../../templates', __FILE__))
    end

    def create_leibniz_yaml(driver)
      template '.leibniz.yml.erb', '.leibniz.yml', {:driver => driver} 
    end

    def create_skeleton_feature
      directory 'features'
    end

    def append_to_gitignore(line)
      create_file(".gitignore") unless File.exists?(File.join(destination_root, ".gitignore"))
      if IO.readlines(File.join(destination_root, ".gitignore")).grep(%r{^#{line}}).empty?
        append_to_file(".gitignore", "#{line}\n")
      end
    end
    
end

LeibnizCli.start