Class: Pineapples::Parser

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

Class Method Summary collapse

Class Method Details

.parse(args) ⇒ Object



3
4
5
6
7
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
# File 'lib/pineapples/parser.rb', line 3

def self.parse(args)
  options = OpenStruct.new
  options.app_name = nil
  options.testing = false

  parser = OptionParser.new do |opts|
    opts.banner = 'Usage: pineapples [options] NEW_APP_DIRECTORY'

    opts.on('-t', '--testing', 'Runs pineapples in testing mode, without git setup') do
      options.testing = true
    end

    opts.on('-h', '--help', 'Show pineapples usage') do
      self.usage_and_exit(opts)
    end

    opts.on_tail('-v', '--version', 'Show version') do
      puts Pineapples::VERSION
      exit 1
    end
  end

  begin
    parser.parse!
    options.app_name = ARGV.first

    raise OptionParser::InvalidOption if options.app_name.nil?

    options
  rescue OptionParser::InvalidOption
    self.usage_and_exit(parser)
  end
end

.usage_and_exit(parser) ⇒ Object



37
38
39
40
# File 'lib/pineapples/parser.rb', line 37

def self.usage_and_exit(parser)
  say parser
  exit 1
end