Sha256: b399ebcab2eb5c1fd0b8572e16992a027bff91d518d29e09c91621463ce8f15e

Contents?: true

Size: 1.54 KB

Versions: 63

Compression:

Stored size: 1.54 KB

Contents

module Vagrant
  module Action
    module Builtin
      # This class asks the user to confirm some sort of question with
      # a "Y/N" question. The only parameter is the text to ask the user.
      # The result is placed in `env[:result]` so that it can be used
      # with the {Call} class.
      class Confirm
        # For documentation, read the description of the {Confirm} class.
        #
        # @param [String] message The message to ask the user.
        # @param [Symbol] force_key The key that if present and true in
        #   the environment hash will skip the confirmation question.
        def initialize(app, env, message, force_key=nil, **opts)
          @app      = app
          @message  = message
          @force_key = force_key
          @allowed  = opts[:allowed]
        end

        def call(env)
          choice = nil

          # If we have a force key set and we're forcing, then set
          # the result to "Y"
          choice = "Y" if @force_key && env[@force_key]

          if !choice
            while true
              # If we haven't chosen yes, then ask the user via TTY
              choice = env[:ui].ask(@message)

              # If we don't have an allowed set just exit
              break if !@allowed
              break if @allowed.include?(choice)
            end
          end

          # The result is only true if the user said "Y"
          env[:result] = choice && choice.upcase == "Y"
          env["#{@force_key}_result".to_sym] = env[:result]

          @app.call(env)
        end
      end
    end
  end
end

Version data entries

63 entries across 56 versions & 8 rubygems

Version Path
vagrant-unbundled-2.3.6.0 lib/vagrant/action/builtin/confirm.rb
tamtam-vagrant-reload-1.2.1 vendor/cache/vagrant-2092df529ae7/lib/vagrant/action/builtin/confirm.rb
vagrant-unbundled-2.3.3.0 lib/vagrant/action/builtin/confirm.rb
vagrant-unbundled-2.3.2.0 lib/vagrant/action/builtin/confirm.rb
vagrant-unbundled-2.2.19.0 lib/vagrant/action/builtin/confirm.rb
vagrant-unbundled-2.2.18.0 lib/vagrant/action/builtin/confirm.rb
vagrant-unbundled-2.2.16.0 lib/vagrant/action/builtin/confirm.rb
vagrant-unbundled-2.2.14.0 lib/vagrant/action/builtin/confirm.rb
vagrant-aws-mkubenka-0.7.2.pre.24 vendor/bundle/ruby/2.7.0/bundler/gems/vagrant-22795b161bf6/lib/vagrant/action/builtin/confirm.rb
vagrant-unbundled-2.2.10.0 lib/vagrant/action/builtin/confirm.rb
vagrant-unbundled-2.2.9.0 lib/vagrant/action/builtin/confirm.rb
vagrant-unbundled-2.2.8.0 lib/vagrant/action/builtin/confirm.rb
vagrant-unbundled-2.2.7.0 lib/vagrant/action/builtin/confirm.rb
vagrant-unbundled-2.2.6.2 lib/vagrant/action/builtin/confirm.rb
vagrant-unbundled-2.2.6.1 lib/vagrant/action/builtin/confirm.rb
vagrant-unbundled-2.2.6.0 lib/vagrant/action/builtin/confirm.rb
vagrant-unbundled-2.2.5.0 lib/vagrant/action/builtin/confirm.rb
vagrant-unbundled-2.2.4.0 lib/vagrant/action/builtin/confirm.rb
vagrant-unbundled-2.2.3.0 lib/vagrant/action/builtin/confirm.rb
vagrant-unbundled-2.2.2.0 lib/vagrant/action/builtin/confirm.rb