Class: FixTSVConflict::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/fix_tsv_conflict/cli.rb

Instance Method Summary collapse

Instance Method Details

#executableObject



43
44
45
# File 'lib/fix_tsv_conflict/cli.rb', line 43

def executable
  File.basename($0)
end

#handle_argv(argv) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/fix_tsv_conflict/cli.rb', line 19

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

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

  [path, options]
end

#option_parser(options) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/fix_tsv_conflict/cli.rb', line 30

def option_parser(options)
  OptionParser.new do |op|
    op.banner = "Usage: \#{executable} [<options>] <tsv>\nOptions:\n    BANNER\n\n    op.on \"-O\", \"--override\", \"Override source file\" do\n      options[:override] = true\n    end\n  end\nend\n"

#run(argv = ARGV) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/fix_tsv_conflict/cli.rb', line 6

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