class Dotfiler::Shell

Constants

TERMINATION_CODES

Attributes

error[R]
input[R]
output[R]

Public Class Methods

new(output: $stdout, input: $stdin, error: $stderr) click to toggle source
# File lib/dotfiler/shell.rb, line 9
def initialize(output: $stdout, input: $stdin, error: $stderr)
  @output = output
  @error = error
  @input = input
end

Public Instance Methods

print(content, type = nil) click to toggle source
prompt(text, available_answers = {}) click to toggle source
# File lib/dotfiler/shell.rb, line 26
def prompt(text, available_answers = {})
  question = text

  if available_answers.any?
    question += "\n\n"
    available_answers.each { |key, details| question += "  #{key}) #{details[:desc]}\n" }
  else
    available_answers = default_prompt_answer
    question += " [y/N] "
  end

  print(question)

  answer_key = input.gets.strip.downcase

  return :other unless available_answers.key?(answer_key)

  available_answers[answer_key].fetch(:value)
end
terminate(type, message: nil) click to toggle source
# File lib/dotfiler/shell.rb, line 46
def terminate(type, message: nil)
  print(message, type) unless message.nil?
  exit(TERMINATION_CODES[type])
end

Private Instance Methods

default_prompt_answer() click to toggle source
# File lib/dotfiler/shell.rb, line 55
def default_prompt_answer
  { "y" => { value: :yes }, "n" => { value: :no } }
end