Class: Biff::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/biff/options.rb

Constant Summary collapse

ARGS =
{
  debug: 'Debug IMAP connection',
  file: ['Config file', 'FILE', '~/.biff.yaml']
}.freeze

Instance Method Summary collapse

Instance Method Details

#configObject



42
43
44
# File 'lib/biff/options.rb', line 42

def config
  @config ||= YAML.parse(File.open(File.expand_path(file))).transform
end

#parse!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
38
39
40
# File 'lib/biff/options.rb', line 12

def parse!
  parser = OptionParser.new do |o|
    o.banner = 'Usage: biff [options]'

    ARGS.each do |k, v|
      default = false

      if v.is_a?(Array)
        default = v[2]
        v = ["#{v[0]} (default #{v[2]})", v[1]]
      end

      set(k, default)
      on(o, k, *v)
    end

    on(o, :help, 'Print help') do
      puts parser
      exit
    end

    on(o, :version, "Print version (#{Biff::VERSION})") do
      puts Biff::VERSION
      exit
    end
  end

  parser.parse!(ARGV)
end