Module: Homebrew::Ask Private

Extended by:
Utils::Output::Mixin
Defined in:
ask.rb

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Class Method Summary collapse

Methods included from Utils::Output::Mixin

issue_reporting_message, odebug, odeprecated, odie, odisabled, ofail, oh1, oh1_title, ohai, ohai_title, onoe, opoo, opoo_outside_github_actions, opoo_without_github_actions_annotation, pretty_deprecated, pretty_disabled, pretty_duration, pretty_install_status, pretty_installed, pretty_outdated, pretty_uninstalled, pretty_upgradable

Class Method Details

.confirm?(action:) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'ask.rb', line 12

def self.confirm?(action:)
  return false if !$stdin.tty? || !$stdout.tty?

  ohai "Do you want to proceed with the #{action}? [y/n]"
  loop do
    result = begin
      $stdin.getch
    rescue Interrupt
      exit 1
    end
    exit 1 unless result

    result = result.chomp.strip.downcase
    if result == "y"
      return true
    # N, Escape, Ctrl-C and Ctrl-D.
    elsif ["n", "\e", "\u0003", "\u0004"].include?(result)
      exit 1
    else
      puts "Invalid input. Please press 'y' to proceed, or 'n' to abort."
    end
  end
end