Class: Tetra::Bash

Inherits:
Object
  • Object
show all
Includes:
Logging, ProcessRunner
Defined in:
lib/tetra/facades/bash.rb

Overview

runs Bash with tetra-specific options

Instance Method Summary collapse

Methods included from ProcessRunner

#run, #run_interactive

Methods included from Logging

#log

Constructor Details

#initialize(project) ⇒ Bash

Returns a new instance of Bash.



9
10
11
# File 'lib/tetra/facades/bash.rb', line 9

def initialize(project)
  @project = project
end

Instance Method Details

#bashObject

runs bash in a subshell, returns list of commands that were run in the session



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/tetra/facades/bash.rb', line 15

def bash
  Tempfile.open("tetra-history") do |history_file|
    Tempfile.open("tetra-bashrc") do |bashrc_file|
      kit = Tetra::Kit.new(@project)
      ant_path = kit.find_executable("ant")
      ant_in_kit = ant_path != nil
      ant_commandline = Tetra::Ant.commandline(@project.full_path, ant_path)

      mvn_path = kit.find_executable("mvn")
      mvn_in_kit = mvn_path != nil
      mvn_commandline = Tetra::Mvn.commandline(@project.full_path, mvn_path)

      bashrc_content = Bashrc.new(history_file.path, ant_in_kit, ant_commandline, mvn_in_kit, mvn_commandline).to_s
      log.debug "writing bashrc file: #{bashrc_file.path}"
      log.debug bashrc_content

      bashrc_file.write(bashrc_content)
      bashrc_file.flush

      run_interactive("bash --rcfile #{bashrc_file.path} -i")
      history = File.read(history_file)
      log.debug "history contents:"
      log.debug history

      history.split("\n").map(&:strip)
    end
  end
end