Class: Ghundle::OptionsParser
- Inherits:
-
Object
- Object
- Ghundle::OptionsParser
- 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
-
#initialize(args) ⇒ OptionsParser
constructor
A new instance of OptionsParser.
- #parse ⇒ Object
- #usage ⇒ Object
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
#parse ⇒ Object
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 = OpenStruct.new parser = OptionParser.new do |o| o. = 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) end |
#usage ⇒ Object
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 |