Class: FixTSVConflict::CLI
- Inherits:
-
Object
- Object
- FixTSVConflict::CLI
- Defined in:
- lib/fix_tsv_conflict/cli.rb
Instance Method Summary collapse
- #executable ⇒ Object
- #handle_argv(argv) ⇒ Object
- #option_parser(options) ⇒ Object
- #run(argv = ARGV) ⇒ Object
Instance Method Details
#executable ⇒ Object
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) = {} op = option_parser() op.parse!(argv) path = argv.shift abort(op.help) if path.nil? [path, ] 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() OptionParser.new do |op| op. = "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, = handle_argv(argv) source = File.read(path) output = Repairman.new.repair(source) if [:override] File.open(path, "w") { |f| f.write(output) } else puts output end end |