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
29
30
31
# File 'lib/executor.rb', line 9

def execute(cmd, args)
  if @config.janked
    subdir = @config.pwd.sub(@config.janked_local_path, '')
    gp_workind_dir = "#{@config.janked_gopath}#{subdir}"

    Dir.chdir(gp_workind_dir) 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("🚀  #{gp_workind_dir}> #{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



33
34
35
36
37
38
39
# File 'lib/executor.rb', line 33

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