Sha256: dcf8cb4adc2cb473a8d15ff30005a24660fd13fef7c98cedb33b9020fc37a30e

Contents?: true

Size: 727 Bytes

Versions: 3

Compression:

Stored size: 727 Bytes

Contents

module Runbook
  class Toolbox
    attr_reader :prompt

    def initialize
      @prompt = TTY::Prompt.new
    end

    def ask(msg, default: nil, echo: true)
      prompt.ask(msg, default: default, echo: echo)
    end

    def expand(msg, choices)
      prompt.expand(msg, choices)
    end

    def yes?(msg)
      begin
        prompt.yes?(msg)
      rescue TTY::Prompt::ConversionError
        err_msg = "Unknown input: Please type 'y' or 'n'."
        warn(err_msg)
        retry
      end
    end

    def output(msg)
      prompt.say(msg)
    end

    def warn(msg)
      prompt.warn(msg)
    end

    def error(msg)
      prompt.error(msg)
    end

    def exit(return_value)
      super(return_value)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
runbook-0.16.1 lib/runbook/toolbox.rb
runbook-0.16.0 lib/runbook/toolbox.rb
runbook-0.15.0 lib/runbook/toolbox.rb