Module: Options

Includes:
Version
Defined in:
lib/options.rb

Overview

Handle command line options

Constant Summary collapse

<<-EOS
Usage: diff ... | riff
Colors diff and highlights what parts of changed lines have changed.

Git integration:
    git config --global pager.diff riff
    git config --global pager.show riff
EOS

Instance Method Summary collapse

Methods included from Version

#dirty?, #git_branch, #git_version, #rubygems_version, #semantic_version, #semantify_git_version, #version

Instance Method Details

#create_optsObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/options.rb', line 17

def create_opts
  return Slop::Options.new do |o|
    o.banner = BANNER
    o.separator 'Options:'
    o.on '--version', 'Print version information and exit' do
      puts "riff #{version}"
      puts
      puts 'Developed at http://github.com/walles/riff'
      puts
      puts 'Get the source code:'
      puts '  git clone [email protected]:walles/riff.git'

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

#handle_optionsObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/options.rb', line 38

def handle_options
  opts = create_opts()

  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