lib/serverspec/setup.rb in serverspec-0.1.6 vs lib/serverspec/setup.rb in serverspec-0.1.7

- old
+ new

@@ -1,13 +1,30 @@ require 'fileutils' module Serverspec class Setup def self.run - print "Input target host name: " - @hostname = gets.chomp + prompt = <<-EOF +Select a backend type: + 1) SSH + 2) Exec (local) + +Select number: +EOF + print prompt.chop + num = gets.to_i - 1 + puts + + @backend_type = [ 'Ssh', 'Exec' ][num] + if @backend_type == 'Ssh' + print "Input target host name: " + @hostname = gets.chomp + else + @hostname = 'localhost' + end + prompt = <<-EOF Select OS type of target host: 1) Red Hat @@ -80,23 +97,31 @@ require 'serverspec' require 'pathname' require 'net/ssh' RSpec.configure do |c| + ### include backend helper ### ### include os helper ### - c.before do + ### include backend conf ### +end +EOF + + if not @backend_type.nil? + content.gsub!(/### include backend helper ###/, "c.include(Serverspec::#{@backend_type}Helper)") + if @backend_type == 'Ssh' + content.gsub!(/### include backend conf ###/, "c.before do host = File.basename(Pathname.new(example.metadata[:location]).dirname) if c.host != host c.ssh.close if c.ssh c.host = host options = Net::SSH::Config.for(c.host) user = options[:user] || Etc.getlogin c.ssh = Net::SSH.start(c.host, user, options) end end -end -EOF - +") + end + end if not @os_type.nil? content.gsub!(/### include os helper ###/, "c.include(Serverspec::#{@os_type}Helper)") end if File.exists? 'spec/spec_helper.rb'