Class: Raykit::Parser

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

Class Method Summary collapse

Class Method Details

.parse(options) ⇒ Object



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
# File 'lib/raykit/console.rb', line 8

def self.parse(options)
    args = Options.new("world")
    opt_parser = OptionParser.new do |opts|
        opts.banner = "Usage: raykit [options]"
        opts.on('-l','--list [PATTERN]','list remotes') do |pattern|
            Raykit::Git::remote_urls.each{|url| 
                if(pattern.nil? || url.include?(pattern))
                    puts Rainbow(url).yellow.bright
                end
            }
            exit
        end

        opts.on('-i','--import','import remotes') do |import|
            puts 'scanning...'
            scanned_remotes = Raykit::Git::scan_remote_urls
            remotes = Raykit::Git::remote_urls
            count = 0
            scanned_remotes.each{|remote|
                if(!remotes.include?(remote))
                    puts "imported " + Rainbow(remote).yellow.bright
                    remotes.insert(0,remote)
                    count = count + 1
                end
            }
            if(count > 0)
                puts 'updating Raykit::Git::remote_urls'
                Raykit::Git::remote_urls = remotes
            end
            exit
        end

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

    opt_parser.parse!(options)
    return args
end