Module: PDK::CLI::Exec

Defined in:
lib/pdk/cli/exec.rb

Defined Under Namespace

Classes: Command

Class Method Summary collapse

Class Method Details

.bundle(*args) ⇒ Object



30
31
32
33
34
# File 'lib/pdk/cli/exec.rb', line 30

def self.bundle(*args)
  ensure_bin_present!(bundle_bin, 'bundler')

  execute(bundle_bin, *args)
end

.bundle_binObject



36
37
38
39
40
41
# File 'lib/pdk/cli/exec.rb', line 36

def self.bundle_bin
  bundle_bin = Gem.win_platform? ? 'bundle.bat' : 'bundle'
  vendored_bin_path = File.join('private', 'ruby', PDK::Util::RubyVersion.active_ruby_version, 'bin', bundle_bin)

  try_vendored_bin(vendored_bin_path, bundle_bin)
end

.ensure_bin_present!(bin_path, bin_name) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/pdk/cli/exec.rb', line 22

def self.ensure_bin_present!(bin_path, bin_name)
  message = _('Unable to find `%{name}`. Check that it is installed and try again.') % {
    name: bin_name,
  }

  raise PDK::CLI::FatalError, message unless TTY::Which.exist?(bin_path)
end

.execute(*cmd) ⇒ Object



14
15
16
# File 'lib/pdk/cli/exec.rb', line 14

def self.execute(*cmd)
  Command.new(*cmd).execute!
end

.execute_with_env(env, *cmd) ⇒ Object



18
19
20
# File 'lib/pdk/cli/exec.rb', line 18

def self.execute_with_env(env, *cmd)
  Command.new(*cmd).tap { |c| c.environment = env }.execute!
end

.try_vendored_bin(vendored_bin_path, fallback) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/pdk/cli/exec.rb', line 43

def self.try_vendored_bin(vendored_bin_path, fallback)
  unless PDK::Util.package_install?
    PDK.logger.debug(_("PDK package installation not found. Trying '%{fallback}' from the system PATH instead.") % {
      fallback: fallback,
    })
    return fallback
  end

  vendored_bin_full_path = File.join(PDK::Util.pdk_package_basedir, vendored_bin_path)

  unless File.exist?(vendored_bin_full_path)
    PDK.logger.debug(_("Could not find '%{vendored_bin}' in PDK package. Trying '%{fallback}' from the system PATH instead.") % {
      fallback: fallback,
      vendored_bin: vendored_bin_full_path,
    })
    return fallback
  end

  PDK.logger.debug(_("Using '%{vendored_bin}' from PDK package.") % { vendored_bin: vendored_bin_full_path })
  vendored_bin_full_path
end