Class: LicenseAcceptance::PromptAcceptance

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/license_acceptance/prompt_acceptance.rb

Constant Summary collapse

WIDTH =
50.freeze
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) ⇒ PromptAcceptance

Returns a new instance of PromptAcceptance.



12
13
14
# File 'lib/license_acceptance/prompt_acceptance.rb', line 12

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

Instance Attribute Details

#outputObject (readonly)

Returns the value of attribute output.



10
11
12
# File 'lib/license_acceptance/prompt_acceptance.rb', line 10

def output
  @output
end

Instance Method Details

#request(missing_licenses, &persist_callback) ⇒ Object



22
23
24
25
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
# File 'lib/license_acceptance/prompt_acceptance.rb', line 22

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

  acceptance_question = "Do you accept the #{c} product license#{s} (#{YES}/no)?"
  output.puts "  \#{BORDER}\n              Chef License Acceptance\n\n  Before you can continue, \#{c} product license\#{s}\n  must be accepted. View the license at\n  https://www.chef.io/end-user-license-agreement/\n\n  License\#{s} that need accepting:\n    * \#{missing_licenses.map(&:pretty_name).join(\"\\n  * \")}\n\n  \#{acceptance_question}\n\n  EOM\n\n  if ask(output, c, s, persist_callback)\n    output.puts BORDER\n    return true\n  end\n\n  output.puts <<~EOM\n\n  If you do not accept this license you will\n  not be able to use Chef products.\n\n  \#{acceptance_question}\n\n  EOM\n\n  answer = ask(output, c, s, persist_callback)\n  if answer != \"yes\"\n    output.puts BORDER\n  end\n  return answer\nend\n"