Class: Dictuby::ArgsParser

Inherits:
Object
  • Object
show all
Defined in:
lib/dictuby/args_parser.rb

Class Method Summary collapse

Class Method Details

.parse(args) ⇒ Object



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
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/dictuby/args_parser.rb', line 4

def self.parse(args)
    options = {}

    args << '--help' if args.empty?

    OptionParser.new do |o|
        o.on(
            '-h', 
            '--help', 
            'Display this message'
        ) do
            puts o; exit 
        end

        o.on(
            '-l',
            '--list-dicts',
            'List available dictionaries'
        ) do |b|
            options[:list] = b
        end

        o.on(
            '-g',
            '--get-dict',
            'Display current active dictionary'
        ) do |b|
            options[:get] = b
        end

        o.on(
            '-s DICTIONARY',
            '--set-dict DICTIONARY',
            'Set active dictionary'
        ) do |d| 
            options[:set] = d
        end
        o.on('QUERY') {}
        o.parse!
    end

    options
end