Class: Jank::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/executor.rb

Direct Known Subclasses

Go

Instance Method Summary collapse

Constructor Details

#initialize(c) ⇒ Executor

Returns a new instance of Executor.



5
6
7
# File 'lib/executor.rb', line 5

def initialize(c)
  @config = c
end

Instance Method Details

#execute(cmd, args) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/executor.rb', line 9

def execute(cmd, args)
  if @config.janked
    Dir.chdir(@config.janked_gopath) do
      janked_args = Array.new
      args.each do |a|
        if a.start_with? @config.janked_local_path
          janked_args << a.sub(@config.janked_local_path, @config.janked_gopath)
        else
          janked_args << a
        end
      end

      Jank.debug_log("🚀  #{@config.janked_gopath}> #{cmd} #{janked_args.inspect}")
      run(cmd, janked_args)
    end
  else
    Jank.debug_log("🚀  #{cmd} #{args.inspect}")
    run(cmd, args)
  end
end

#run(cmd, args) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/executor.rb', line 30

def run(cmd, args)
  IO.popen(@config.env, [cmd, *args]) do |pipe|
    while line = pipe.gets
      puts line
    end
  end
end