Class: Bolt::Plugin::Prompt

Inherits:
Object
  • Object
show all
Defined in:
lib/bolt/plugin/prompt.rb

Instance Method Summary collapse

Constructor Details

#initialize(*_args) ⇒ Prompt

Returns a new instance of Prompt.



7
# File 'lib/bolt/plugin/prompt.rb', line 7

def initialize(*_args); end

Instance Method Details

#hooksObject



13
14
15
# File 'lib/bolt/plugin/prompt.rb', line 13

def hooks
  [:resolve_reference]
end

#nameObject



9
10
11
# File 'lib/bolt/plugin/prompt.rb', line 9

def name
  'prompt'
end

#resolve_reference(opts) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/bolt/plugin/prompt.rb', line 21

def resolve_reference(opts)
  # rubocop:disable Style/GlobalVars
  $future ? STDERR.print("#{opts['message']}: ") : STDOUT.print("#{opts['message']}: ")
  value = STDIN.noecho(&:gets).chomp
  $future ? STDERR.puts : STDOUT.puts
  # rubocop:enable Style/GlobalVars

  value
end

#validate_resolve_reference(opts) ⇒ Object



17
18
19
# File 'lib/bolt/plugin/prompt.rb', line 17

def validate_resolve_reference(opts)
  raise Bolt::ValidationError, "Prompt requires a 'message'" unless opts['message']
end