Class: Ghundle::OptionsParser

Inherits:
Object
  • Object
show all
Defined in:
lib/ghundle/options_parser.rb

Overview

Contains the logic for extracting command-line options. Relies on ‘optparse’ from the standard library.

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ OptionsParser

Returns a new instance of OptionsParser.



9
10
11
# File 'lib/ghundle/options_parser.rb', line 9

def initialize(args)
  @args = args
end

Instance Method Details

#parseObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ghundle/options_parser.rb', line 33

def parse
  options = OpenStruct.new

  parser = OptionParser.new do |o|
    o.banner = usage

    o.on_tail("-h", "--help", "Show this message") do
      puts o
      exit
    end

    o.on_tail("--version", "Show version") do
      puts VERSION
      exit
    end
  end

  parser.parse!(@args)
  options
end

#usageObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ghundle/options_parser.rb', line 13

def usage
  [
    '',
    'Usage: ghundle <command> [options...]',
    '',
    'Commands:',
    '',
    '  ghundle list-all',
    '  ghundle run <hook-name>',
    '  ghundle fetch github.com/<username>/<repo>/<path/to/hook/dir>',
    '  ghundle install <hook-name>',
    '  ghundle install github.com/<username>/<repo>/<path/to/hook/dir>',
    '  ghundle list-installed',
    '  ghundle uninstall <hook-name>',
    '',
    'Options:',
    '',
  ].join("\n")
end