Sha256: 2e8f3db84cc28a3a1c0fca1146ceb24a1447999dc67364967cc8bd2651db0f24

Contents?: true

Size: 677 Bytes

Versions: 9

Compression:

Stored size: 677 Bytes

Contents

# frozen_string_literal: true

require 'thor'

module Dsu
  module Support
    module Ask
      def ask(prompt)
        options = {}
        Thor::LineEditor.readline(prompt, options)
      end

      def yes?(prompt, options: {})
        auto_prompt = auto_prompt(prompt, options)

        return auto_prompt unless auto_prompt.nil?

        Thor::Base.shell.new.yes?(prompt)
      end

      private

      def auto_prompt(prompt, options)
        prompt = Utils.strip_escapes(prompt)
        @auto_prompt ||= begin
          value = options.dig('prompts', prompt)
          value = (value == 'true' unless value.nil?)
          value
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
dsu-2.0.8 lib/dsu/support/ask.rb
dsu-2.0.7 lib/dsu/support/ask.rb
dsu-2.0.6 lib/dsu/support/ask.rb
dsu-2.0.5 lib/dsu/support/ask.rb
dsu-2.0.4 lib/dsu/support/ask.rb
dsu-2.0.3 lib/dsu/support/ask.rb
dsu-2.0.2 lib/dsu/support/ask.rb
dsu-2.0.1 lib/dsu/support/ask.rb
dsu-2.0.0.alpha.1 lib/dsu/support/ask.rb