Sha256: 643ad61ccdae8662621b8423fab8508eb23cc9be8499baea446ce035d9e4e300

Contents?: true

Size: 901 Bytes

Versions: 6

Compression:

Stored size: 901 Bytes

Contents

require "fix_tsv_conflict/repairman"
require "optparse"

module FixTSVConflict
  class CLI
    def run(argv = ARGV)
      path, options = handle_argv(argv)

      source = File.read(path)
      output =  Repairman.new.repair(source)

      if options[:override]
        File.open(path, "w") { |f| f.write(output) }
      else
        puts output
      end
    end

    def handle_argv(argv)
      options = {}
      op = option_parser(options)
      op.parse!(argv)

      path = argv.shift
      abort(op.help) if path.nil?

      [path, options]
    end

    def option_parser(options)
      OptionParser.new do |op|
        op.banner = <<-BANNER
Usage: #{executable} [<options>] <tsv>
Options:
        BANNER

        op.on "-O", "--override", "Override source file" do
          options[:override] = true
        end
      end
    end

    def executable
      File.basename($0)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
fix_tsv_conflict-0.3.0 lib/fix_tsv_conflict/cli.rb
fix_tsv_conflict-0.2.1 lib/fix_tsv_conflict/cli.rb
fix_tsv_conflict-0.2.0 lib/fix_tsv_conflict/cli.rb
fix_tsv_conflict-0.1.2 lib/fix_tsv_conflict/cli.rb
fix_tsv_conflict-0.1.1 lib/fix_tsv_conflict/cli.rb
fix_tsv_conflict-0.1.0 lib/fix_tsv_conflict/cli.rb