Module: Dply::Helper

Instance Method Summary collapse

Instance Method Details

#cmd(command, env: {}, bundled_env: false, return_output: false, display: :bullet) ⇒ Object



11
12
13
14
15
16
# File 'lib/dply/helper.rb', line 11

def cmd(command, env: {}, bundled_env: false, return_output: false, display: :bullet)
  logger.command command, mode: display
  new_env = Env.build_env(env, bundled_env: bundled_env)
  cmd = Command.new command, env: new_env, shell: false
  return_output ? cmd.capture : cmd.run
end

#error(msg) ⇒ Object

Raises:



52
53
54
# File 'lib/dply/helper.rb', line 52

def error(msg)
  raise ::Dply::Error, msg
end

#gitObject



48
49
50
# File 'lib/dply/helper.rb', line 48

def git
  Git
end

#loggerObject



44
45
46
# File 'lib/dply/helper.rb', line 44

def logger
  Logger.logger
end

#sh(command, env: {}, bundled_env: false, return_output: false, display: :bullet) ⇒ Object



18
19
20
21
22
23
# File 'lib/dply/helper.rb', line 18

def sh(command, env: {}, bundled_env: false, return_output: false, display: :bullet)
  logger.command command, mode: display
  new_env = Env.build_env(env, bundled_env: bundled_env)
  cmd = Command.new command, env: new_env, shell: true
  return_output ? cmd.capture : cmd.run
end


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/dply/helper.rb', line 25

def symlink(src, dst)
  if File.symlink? dst
    # to_s to handle pathnames
    return true if File.readlink(dst) == src.to_s
    Dir.mktmpdir("sym-", "./") do |d|
      dst_tmp = "#{d}/#{File.basename dst}"
      FileUtils.ln_s src, dst_tmp

      # using 'mv' here as FileUtils.mv doesn't replace a symlink which points
      # to a directory
      cmd ["mv", dst_tmp, File.dirname(dst)], display: false
    end
  elsif File.exist? dst
    error "cannot create symlink #{dst} => #{src}"
  else
    FileUtils.ln_s src, dst
  end
end