Class: LicenseAcceptance::Strategy::Prompt

Inherits:
Base
  • Object
show all
Includes:
Logger
Defined in:
lib/license_acceptance/strategy/prompt.rb

Overview

Interactive prompt for accepting and persistence license acceptance, or failing with custom exit code

Constant Summary collapse

WIDTH =
50
PASTEL =
Pastel.new
BORDER =
"+---------------------------------------------+".freeze
YES =
PASTEL.green.bold("yes")
CHECK =
PASTEL.green("")

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logger

initialize, logger, #logger

Constructor Details

#initialize(config) ⇒ Prompt

Returns a new instance of Prompt.



16
17
18
# File 'lib/license_acceptance/strategy/prompt.rb', line 16

def initialize(config)
  @output = config.output
end

Instance Attribute Details

#outputObject (readonly)

Returns the value of attribute output.



14
15
16
# File 'lib/license_acceptance/strategy/prompt.rb', line 14

def output
  @output
end

Instance Method Details

#request(missing_licenses, &persist_callback) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
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/license_acceptance/strategy/prompt.rb', line 26

def request(missing_licenses, &persist_callback)
  logger.debug("Requesting a license for #{missing_licenses.map(&:id)}")
  c = missing_licenses.size
  s = c > 1 ? "s" : ""

  acceptance_question = "Do you accept the #{c} product license#{s} (#{YES}/no)?"
  output.puts <<~EOM
    #{BORDER}
                Chef License Acceptance

    Before you can continue, #{c} product license#{s}
    must be accepted. View the license at
    https://www.chef.io/end-user-license-agreement/

    License#{s} that need accepting:
      * #{missing_licenses.map(&:pretty_name).join("\n  * ")}

    #{acceptance_question}

  EOM

  if ask(output, c, s, persist_callback)
    output.puts BORDER
    return true
  end

  output.puts <<~EOM

    If you do not accept this license you will
    not be able to use Chef products.

    #{acceptance_question}

  EOM

  answer = ask(output, c, s, persist_callback)
  if answer != "yes"
    output.puts BORDER
  end
  answer
end