class Translatomatic::CLI::Base

Base class for command line interface classes

Private Class Methods

thor_options(klass, object) click to toggle source
# File lib/translatomatic/cli/base.rb, line 17
def thor_options(klass, object)
  Translatomatic::Option.options_from_object(object).each do |option|
    next if option.hidden
    name = option.name.to_s.dasherize
    klass.method_option name, option.to_thor
  end
end

Private Instance Methods

add_table_heading(rows, headings) click to toggle source
# File lib/translatomatic/cli/base.rb, line 78
def add_table_heading(rows, headings)
  underscores = headings.collect { |i| i.gsub(/\w/, '=') }
  [headings, underscores] + rows
end
conf() click to toggle source
# File lib/translatomatic/cli/base.rb, line 62
def conf
  Translatomatic.config
end
create_config() click to toggle source
# File lib/translatomatic/cli/base.rb, line 47
def create_config
  Translatomatic::Config::Settings.new(runtime: options)
end
empty_array?(value) click to toggle source
# File lib/translatomatic/cli/base.rb, line 74
def empty_array?(value)
  value.is_a?(Array) && value.empty?
end
finish_log() click to toggle source
# File lib/translatomatic/cli/base.rb, line 58
def finish_log
  log.finish if log.respond_to?(:finish)
end
handle_run_error(e) click to toggle source
# File lib/translatomatic/cli/base.rb, line 51
def handle_run_error(e)
  finish_log
  log.error(e.message)
  log.debug(e.backtrace.join("\n"))
  raise e if ENV['TEST'] # reraise exceptions in test
end
parse_list(list, default = []) click to toggle source
# File lib/translatomatic/cli/base.rb, line 26
def parse_list(list, default = [])
  # use the default list if the list is empty
  list = default if list.nil? || list.empty?
  list = [list] unless list.is_a?(Array)
  # split list entries on ','
  list.compact.collect { |i| i.split(/[, ]/) }.flatten.compact
end
rainbow() click to toggle source
# File lib/translatomatic/cli/base.rb, line 66
def rainbow
  @rainbow ||= begin
    rainbow = Rainbow.new
    rainbow.enabled = !conf.get(:no_wank)
    rainbow
  end
end
run() { || ... } click to toggle source

run the give code block, display exceptions.

# File lib/translatomatic/cli/base.rb, line 35
def run
  Translatomatic.config = create_config
  @dry_run = conf.get(:dry_run)
  log.level = ::Logger::DEBUG if conf.get(:debug)
  log.info(t('cli.dry_run')) if @dry_run
  yield
rescue Interrupt
  puts "\n" + t('cli.aborted')
rescue StandardError => e
  handle_run_error(e)
end