Class: Raykit::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/raykit/console.rb

Overview

Parses the command line arguments for the Raykit console application

Class Method Summary collapse

Class Method Details

.parse(options) ⇒ Object



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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/raykit/console.rb', line 6

def self.parse(options)
    hash=Hash.new
    opt_parser = OptionParser.new do |opts|
        opts.banner = "Usage: raykit [options]"
        opts.on('-l','--list [PATTERN]','list remotes') do |pattern|
            hash[:verb]="list"
            hash[:pattern]=pattern
            return hash
        end

        opts.on('-i','--import','import remotes') do |import|
            hash[:verb]="import"
            return hash
        end

        opts.on('-r','--rake [PATTERN]','rake [PATTERN]') do |pattern|
            hash[:verb]="rake"
            if(pattern.nil?)
                hash[:pattern] = ''
            else
                hash[:pattern]=pattern
            end
            return hash
        end

        opts.on('-w','--work [PATTERN]','work [PATTERN]') do |pattern|
            hash[:verb]="work"
            if(pattern.nil?)
                hash[:pattern] = ''
            else
                hash[:pattern]=pattern
            end
            return hash
        end

        opts.on('-h','--help','help') do
            puts opts
            exit
        end
    end

    opt_parser.parse!(options)
    hash
end