Class: PDK::CLI::Util::CommandRedirector

Inherits:
TTY::Prompt::AnswersCollector
  • Object
show all
Defined in:
lib/pdk/cli/util/command_redirector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prompt, options = {}) ⇒ CommandRedirector

Override the initialize method because the original one doesn’t work with Ruby 3. rubocop:disable Lint/MissingSuper



13
14
15
16
# File 'lib/pdk/cli/util/command_redirector.rb', line 13

def initialize(prompt, options = {})
  @prompt  = prompt
  @answers = options.fetch(:answers) { {} }
end

Instance Attribute Details

#commandObject

Returns the value of attribute command.



8
9
10
# File 'lib/pdk/cli/util/command_redirector.rb', line 8

def command
  @command
end

Instance Method Details

#pastelObject

rubocop:enable Lint/MissingSuper



19
20
21
# File 'lib/pdk/cli/util/command_redirector.rb', line 19

def pastel
  @pastel ||= Pastel.new
end

#runObject



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

def run
  @prompt.puts "Did you mean '#{pastel.bold(@command)}'?"
  @prompt.yes?('-->')
rescue PDK::CLI::Util::Interview::READER::InputInterrupt
  nil
end

#target_command(cmd) ⇒ Object



23
24
25
# File 'lib/pdk/cli/util/command_redirector.rb', line 23

def target_command(cmd)
  @command = cmd
end