Class: Rpatch::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/rpatch/runner.rb

Class Method Summary collapse

Class Method Details

.runnerObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rpatch/runner.rb', line 9

def runner
    path = "."
    patches = []
    patch_level = 1

    OptionParser.new do |opts|
      opts.banner = "Usage: rpatch [options] [originalfile [patchfile]]"
      opts.on("-p", "--strip num", "Patch level") {|v| patch_level = v.to_i}
      opts.on("-V", "--version", "Show version") do
        puts "Version #{Rpatch::VERSION}"
        exit 0
      end
      opts.on("-v", "--verbose", "More verbose") {Tty.options[:verbose] += 1}
      opts.on("-q", "--quiet", "Less verbose") {Tty.options[:verbose] -= 1}
      opts.on_tail("-h", "--help", "Show this message") do
        puts opts
        exit 0
      end
    end.parse!

    case ARGV.size
    when 0
      patches << STDIN
    when 1
      path = ARGV.shift
      patches << STDIN
    else
      path = ARGV.shift
      until ARGV.empty? do
        patches << ARGV.shift
      end
    end

    result = Patch::apply(path, patches, patch_level)
    exit 1 unless result
end