Sha256: a33b98602bb56f67b10f35224bbbee485e162d0b49f785cdc1e9cb754bfb87f7

Contents?: true

Size: 1.02 KB

Versions: 42

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

require 'eac_cli/runner'
require 'eac_ruby_utils/core_ext'

module EacCli
  module RunnerWith
    module Confirmation
      DEFAULT_CONFIRM_QUESTION_TEXT = 'Confirm?'

      common_concern do
        include ::EacCli::Runner
        enable_settings_provider
        enable_simple_cache
        runner_definition do
          bool_opt '--no', 'Deny confirmation without question.'
          bool_opt '--yes', 'Accept confirmation without question.'
        end
      end

      def confirm?(message = nil)
        return false if parsed.no?
        return true if parsed.yes?

        input(
          message || setting_value(:confirm_question_text, default: DEFAULT_CONFIRM_QUESTION_TEXT),
          bool: true
        )
      rescue ::EacCli::Speaker::InputRequested => e
        fatal_error e.message
      end

      def run_confirm(message = nil)
        yield if confirm?(message)
      end

      private

      def cached_confirm_uncached?(message = nil)
        confirm?(message)
      end
    end
  end
end

Version data entries

42 entries across 42 versions & 2 rubygems

Version Path
eac_cli-0.39.0 lib/eac_cli/runner_with/confirmation.rb
eac_cli-0.38.1 lib/eac_cli/runner_with/confirmation.rb
eac_tools-0.82.0 sub/eac_cli/lib/eac_cli/runner_with/confirmation.rb
eac_tools-0.81.0 sub/eac_cli/lib/eac_cli/runner_with/confirmation.rb
eac_tools-0.80.0 sub/eac_cli/lib/eac_cli/runner_with/confirmation.rb
eac_tools-0.79.0 sub/eac_cli/lib/eac_cli/runner_with/confirmation.rb
eac_tools-0.78.0 sub/eac_cli/lib/eac_cli/runner_with/confirmation.rb
eac_tools-0.77.1 sub/eac_cli/lib/eac_cli/runner_with/confirmation.rb
eac_tools-0.77.0 sub/eac_cli/lib/eac_cli/runner_with/confirmation.rb
eac_cli-0.38.0 lib/eac_cli/runner_with/confirmation.rb
eac_tools-0.76.1 sub/eac_cli/lib/eac_cli/runner_with/confirmation.rb
eac_tools-0.76.0 sub/eac_cli/lib/eac_cli/runner_with/confirmation.rb
eac_tools-0.75.2 sub/eac_cli/lib/eac_cli/runner_with/confirmation.rb
eac_cli-0.37.0 lib/eac_cli/runner_with/confirmation.rb
eac_tools-0.75.1 sub/eac_cli/lib/eac_cli/runner_with/confirmation.rb
eac_tools-0.75.0 sub/eac_cli/lib/eac_cli/runner_with/confirmation.rb
eac_tools-0.74.1 sub/eac_cli/lib/eac_cli/runner_with/confirmation.rb
eac_tools-0.74.0 sub/eac_cli/lib/eac_cli/runner_with/confirmation.rb
eac_cli-0.36.0 lib/eac_cli/runner_with/confirmation.rb
eac_tools-0.73.0 sub/eac_cli/lib/eac_cli/runner_with/confirmation.rb