class TextToCheckstyle::CLI

Public Class Methods

exit_on_failure?() click to toggle source
# File lib/text_to_checkstyle/cli.rb, line 5
def self.exit_on_failure?
  true
end

Public Instance Methods

convert() click to toggle source
# File lib/text_to_checkstyle/cli.rb, line 26
def convert
  setup_logger(options)
  data = \
      if options[:data]
        options[:data]
      elsif options[:file]
        File.read(options[:file])
      elsif !$stdin.tty?
        ARGV.clear
        ARGF.read
      end

  fail(NoInputError) if !data || data.empty?
  params = {
    name: options[:name],
    line: options[:line],
    column: options[:column],
    severity: options[:severity],
    source: options[:source]
  }
  puts ::TextToCheckstyle::Converter.convert(data, params)
rescue StandardError => e
  suggest_messages(options)
  raise e
end
logger() click to toggle source
# File lib/text_to_checkstyle/cli.rb, line 54
def logger
  ::TextToCheckstyle.logger
end
method_missing(method, *args) click to toggle source

stackoverflow.com/a/23955971/104080

# File lib/text_to_checkstyle/cli.rb, line 75
def method_missing(method, *args)
  self.class.start([self.class.default_command, method.to_s] + args)
end
setup_logger(options) click to toggle source
# File lib/text_to_checkstyle/cli.rb, line 58
def setup_logger(options)
  if options[:debug]
    logger.level = Logger::DEBUG
  elsif options[:verbose]
    logger.level = Logger::INFO
  end
  logger.debug(options)
end
suggest_messages(options) click to toggle source
# File lib/text_to_checkstyle/cli.rb, line 67
def suggest_messages(options)
  logger.error 'Have a question? Please ask us:'
  logger.error ISSUE_URL
  logger.error 'options:'
  logger.error options
end
version() click to toggle source
# File lib/text_to_checkstyle/cli.rb, line 12
def version
  puts "TextToCheckstyle version #{::TextToCheckstyle::VERSION}"
end