Module: PDK::CLI::Exec

Defined in:
lib/pdk/cli/exec.rb,
lib/pdk/cli/exec/command.rb,
lib/pdk/cli/exec/interactive_command.rb

Defined Under Namespace

Classes: Command, InteractiveCommand

Class Method Summary collapse

Class Method Details

.bundle(*args) ⇒ Object



41
42
43
44
45
# File 'lib/pdk/cli/exec.rb', line 41

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

  execute(bundle_bin, *args)
end

.bundle_binObject



47
48
49
50
51
52
53
54
# File 'lib/pdk/cli/exec.rb', line 47

def self.bundle_bin
  require 'pdk/util/ruby_version'

  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



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

def self.ensure_bin_present!(bin_path, bin_name)
  require 'tty-which'

  message = format('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



9
10
11
12
13
# File 'lib/pdk/cli/exec.rb', line 9

def self.execute(*cmd)
  require 'pdk/cli/exec/command'

  Command.new(*cmd).execute!
end

.execute_interactive(*cmd) ⇒ Object



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

def self.execute_interactive(*cmd)
  require 'pdk/cli/exec/interactive_command'

  InteractiveCommand.new(*cmd).execute!
end

.execute_interactive_with_env(env, *cmd) ⇒ Object



27
28
29
30
31
# File 'lib/pdk/cli/exec.rb', line 27

def self.execute_interactive_with_env(env, *cmd)
  require 'pdk/cli/exec/interactive_command'

  InteractiveCommand.new(*cmd).tap { |c| c.environment = env }.execute!
end

.execute_with_env(env, *cmd) ⇒ Object



15
16
17
18
19
# File 'lib/pdk/cli/exec.rb', line 15

def self.execute_with_env(env, *cmd)
  require 'pdk/cli/exec/command'

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

.try_vendored_bin(vendored_bin_path, fallback) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/pdk/cli/exec.rb', line 56

def self.try_vendored_bin(vendored_bin_path, fallback)
  require 'pdk/util'

  unless PDK::Util.package_install?
    PDK.logger.debug(format("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)

  require 'pdk/util/filesystem'
  unless PDK::Util::Filesystem.exist?(vendored_bin_full_path)
    PDK.logger.debug(format("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 format("Using '%{vendored_bin}' from PDK package.", vendored_bin: vendored_bin_full_path)
  vendored_bin_full_path
end