Module: Options

Includes:
Version
Defined in:
lib/options.rb

Overview

Handle command line options

Instance Method Summary collapse

Methods included from Version

#git_version, #rubygems_version, #semantify_git_version, #version

Instance Method Details

#handle_optionsObject



8
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
45
# File 'lib/options.rb', line 8

def handle_options
  opts = Slop::Options.new do |o|
    o.banner = "Usage: diff ... | riff\nColors diff and highlights what parts of changed lines have changed.\n\nGit integration:\n  git config --global pager.diff riff\n  git config --global pager.show riff\n"
    o.separator 'Options:'
    o.on '--version', 'Print version information and exit' do
      puts "riff #{version}"
      puts
      puts 'Developed at http://github.com/walles/riff'

      exit
    end
    o.on '-h', '--help', 'Print this help' do
      puts o
      exit
    end
  end

  begin
    opts.parse(ARGV)
  rescue Slop::Error => e
    STDERR.puts "ERROR: #{e}"
    STDERR.puts
    STDERR.puts opts
    exit 1
  end

  if $stdin.isatty
    puts opts
    exit
  end
end