<commit_before>require 'fileutils'

module Serverspec
  class Setup
    def self.run
      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 "Vagrant instance y/n: "
        @vagrant = gets.chomp
        if @vagrant =~ (/(true|t|yes|y|1)$/i)
          @vagrant = true
        else
          @vagrant = false
        end
        print "Auto-configure Vagrant from Vagrantfile? y/n:"
        auto_config = gets.chomp
        if auto_config =~ (/(true|t|yes|y|1)$/i)
          if File.exists?("Vagrantfile")
            vagrant_list = `vagrant status`
            if vagrant_list != ''
              vagrant_list.each_line do |line|
                if match = /([a-z]+[\s]+)(created|not created)[\s](\(virtualbox\)|\(vmware\))/.match(line)
                  puts match[0]
                end
              end
            end

          else
            $stderr.puts "Vagrantfile not found in directory!"
            exit 1
          end
        else

        end

        @vagrant ? print("Input vagrant instance name: ") : print("Input target host name: ")
        @hostname = gets.chomp
     else
        @hostname = 'localhost'
      end

      [ 'spec', "spec/#{@hostname}" ].each { |dir| safe_mkdir(dir) }
      safe_create_spec
      safe_create_spec_helper
      safe_create_rakefile
    end

    def self.safe_create_spec

      content = <<-EOF
require 'spec_helper'

describe package('httpd') do
  it { should be_installed }<commit_msg>Change to give Vagrant instance name<commit_after>require 'fileutils'

module Serverspec
  class Setup
    def self.run
      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 "Vagrant instance y/n: "
        @vagrant = gets.chomp
        if @vagrant =~ (/(true|t|yes|y|1)$/i)
          @vagrant = true
        else
          @vagrant = false
        end
        print "Auto-configure Vagrant from Vagrantfile? y/n:"
        auto_config = gets.chomp
        if auto_config =~ (/(true|t|yes|y|1)$/i)
          if File.exists?("Vagrantfile")
            vagrant_list = `vagrant status`
            if vagrant_list != ''
              vagrant_list.each_line do |line|
                if match = /([a-z]+[\s]+)(created|not created)[\s](\(virtualbox\)|\(vmware\))/.match(line)
                  puts match[1]
                end
              end
            end

          else
            $stderr.puts "Vagrantfile not found in directory!"
            exit 1
          end
        else

        end

        @vagrant ? print("Input vagrant instance name: ") : print("Input target host name: ")
        @hostname = gets.chomp
     else
        @hostname = 'localhost'
      end

      [ 'spec', "spec/#{@hostname}" ].each { |dir| safe_mkdir(dir) }
      safe_create_spec
      safe_create_spec_helper
      safe_create_rakefile
    end

    def self.safe_create_spec

      content = <<-EOF
require 'spec_helper'

describe package('httpd') do
  it { should be_installed }
{'fraction_non_alphanumeric': 0.11546642357945913, 'fraction_numerical': 0.00425402613187481, 'mean_word_length': 1.7851099830795263, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5795937', 'n_tokens_mistral': 1082, 'n_tokens_neox': 1055, 'n_words': 261}