Sha256: af844a31b602dc0b59bf7a5ae1ff8d2ad290e73ad74992a9925f78e37a8c197a

Contents?: true

Size: 1.36 KB

Versions: 10

Compression:

Stored size: 1.36 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)
    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

10 entries across 10 versions & 1 rubygems

Version Path
bolt-2.15.0 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-2.14.0 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-2.13.0 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-2.12.0 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-2.11.1 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-2.11.0 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-2.10.0 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-2.9.0 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-2.8.0 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-2.7.0 bolt-modules/prompt/lib/puppet/functions/prompt.rb