Sha256: 9774152be491e366102e2e1c18ebd8b4bee0c5bcfdc9d1a10acce67b769bc425

Contents?: true

Size: 1.39 KB

Versions: 17

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

require 'bolt/error'

# Display a prompt and wait for a response.
#
# > **Note:** Not available in apply block
Puppet::Functions.create_function(:prompt) do
  # @param prompt The prompt to display.
  # @param options A hash of additional options.
  # @option options [Boolean] sensitive Disable echo back and mark the response as sensitive.
  # @return The response to the prompt.
  # @example Prompt the user if plan execution should continue
  #   $response = prompt('Continue executing plan? [Y\N]')
  # @example Prompt the user for sensitive information
  #   $password = prompt('Enter your password', 'sensitive' => true)
  dispatch :prompt do
    param 'String', :prompt
    optional_param 'Hash[String[1], Any]', :options
    return_type 'Variant[String, Sensitive]'
  end

  def prompt(prompt, options = {})
    unless Puppet[:tasks]
      raise Puppet::ParseErrorWithIssue
        .from_issue_and_stack(Bolt::PAL::Issues::PLAN_OPERATION_NOT_SUPPORTED_WHEN_COMPILING,
                              action: 'prompt')
    end

    options = options.transform_keys(&:to_sym)

    executor = Puppet.lookup(:bolt_executor)
    # Send analytics report
    executor.report_function_call(self.class.name)

    response = executor.prompt(prompt, options)

    if options[:sensitive]
      Puppet::Pops::Types::PSensitiveType::Sensitive.new(response)
    else
      response
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
bolt-2.31.0 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-2.30.0 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-2.29.0 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-2.28.0 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-2.27.0 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-2.26.0 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-2.25.0 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-2.24.1 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-2.24.0 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-2.23.0 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-2.22.0 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-2.21.0 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-2.20.0 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-2.19.0 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-2.18.0 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-2.17.0 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-2.16.0 bolt-modules/prompt/lib/puppet/functions/prompt.rb