Sha256: 57411daea9a1ef2f570c41579415289929a1fe26945a255fe2d3ff7507769612

Contents?: true

Size: 854 Bytes

Versions: 4

Compression:

Stored size: 854 Bytes

Contents

require 'thor'

module PmdTranslateCheckstyleFormat
  class CLI < Thor
    include ::PmdTranslateCheckstyleFormat::Translate
    desc 'translate', 'Exec Translate'
    option :data
    option :file
    option 'cpd-translate', type: :boolean
    def translate
      data = fetch_data(options)
      xml = parse(data)
      if options['cpd-translate']
        checkstyle = trans_cpd(xml)
      elsif
        checkstyle = trans(xml)
      end
      checkstyle.write(STDOUT, 2)
    end

    no_commands do
      def fetch_data(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?

        data
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pmd_translate_checkstyle_format-0.3.0 lib/pmd_translate_checkstyle_format/cli.rb
pmd_translate_checkstyle_format-0.2.2 lib/pmd_translate_checkstyle_format/cli.rb
pmd_translate_checkstyle_format-0.2.1 lib/pmd_translate_checkstyle_format/cli.rb
pmd_translate_checkstyle_format-0.2.0 lib/pmd_translate_checkstyle_format/cli.rb