Class: HGTK::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/hgtk/parser.rb

Class Method Summary collapse

Class Method Details

.run(**kwargs) ⇒ Object



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
# File 'lib/hgtk/parser.rb', line 12

def self.run **kwargs
  # :argv is a convenience to override ARGV, like for testing.
  args = kwargs.fetch :argv, ARGV

  # Command line options.
  options = OpenStruct.new \
    recursive: false
  
  OptionParser.new do |opts|
    opts.banner = "Usage: hgtk [options] command"
    
    opts.on '-h', '--help', 'Display this help screen.' do
      puts opts
      exit
    end
    
    opts.on '-r', 'Search recursively.' do |v|
      options.recursive = true
    end
    
  end.parse! args
  
  command = args.last
  
  # HGTK::Hg.new args.last, **options.to_h
end