Class: PDK::CLI::Exec::InteractiveCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/pdk/cli/exec/interactive_command.rb

Instance Attribute Summary

Attributes inherited from Command

#argv, #context, #environment, #exec_group

Instance Method Summary collapse

Methods inherited from Command

#update_environment

Constructor Details

#initialize(*argv) ⇒ InteractiveCommand

Returns a new instance of InteractiveCommand.



7
8
9
10
11
12
13
14
15
# File 'lib/pdk/cli/exec/interactive_command.rb', line 7

def initialize(*argv)
  @argv = argv

  # Default to running things in the system context.
  @context = :system

  # Extra environment vars to add to base set.
  @environment = {}
end

Instance Method Details

#add_spinner(_message, _opts = {}) ⇒ Object



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

def add_spinner(_message, _opts = {})
  raise _('This method is not implemented for PDK::CLI::Exec::InteractiveCommand')
end

#exec_group=(_val) ⇒ Object



33
34
35
# File 'lib/pdk/cli/exec/interactive_command.rb', line 33

def exec_group=(_val)
  raise _('This method is not implemented for PDK::CLI::Exec::InteractiveCommand')
end

#execute!Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/pdk/cli/exec/interactive_command.rb', line 37

def execute!
  @resolved_env = resolved_env_for_command

  if [:module, :pwd].include?(context)
    mod_root = PDK::Util.module_root

    unless mod_root
      raise PDK::CLI::FatalError, _('Current working directory is not part of a module. (No metadata.json was found.)')
    end

    unless context == :pwd || Dir.pwd == mod_root
      orig_workdir = Dir.pwd
      Dir.chdir(mod_root)
    end

    result = run_process_in_clean_env!
  else
    result = run_process!
  end

  {
    interactive: true,
    stdout: nil,
    stderr: nil,
    exit_code: result[:exit_code],
    duration: result[:duration],
  }
ensure
  Dir.chdir(orig_workdir) if orig_workdir
end

#register_spinner(_spinner, _opts = {}) ⇒ Object



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

def register_spinner(_spinner, _opts = {})
  raise _('This method is not implemented for PDK::CLI::Exec::InteractiveCommand')
end

#timeoutObject



25
26
27
# File 'lib/pdk/cli/exec/interactive_command.rb', line 25

def timeout
  raise _('This method is not implemented for PDK::CLI::Exec::InteractiveCommand')
end

#timeout=(_val) ⇒ Object



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

def timeout=(_val)
  raise _('This method is not implemented for PDK::CLI::Exec::InteractiveCommand')
end