Class: Timekeeper::KeeperOptions

Inherits:
Hash
  • Object
show all
Defined in:
lib/timekeeper/keeper_options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ KeeperOptions

Returns a new instance of KeeperOptions.



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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/timekeeper/keeper_options.rb', line 6

def initialize(args)
  super()

  @opts = OptionParser.new do |o|
    o.banner = "Usage: #{File.basename($0)} [options]"

    o.on("--config FILE", "location of your configuration file - default is ./timekeeper.yml") do |file|
      self[:config] = file
    end
    
    o.on('-n', '--name NAME', 'Who did it?') do |name|
      self[:name] = name
    end        

    o.on('-t', '--title TITLE', 'What do you want to register?') do |title|
      self[:title] = title
    end

    o.on('-c', '--target TARGET', 'Who is going to pay?') do |target|
      self[:target] = target
    end

    o.on('-s', '--time TIME', 'How long did it take?') do |time|
      self[:time] = time
    end

    o.on('-m', '--description DESCRIPTION', 'More? You want to be more specific?') do |description|
      self[:description] = description
    end

    o.on('-d', '--date DATE', 'When exactly did it happen?') do |date|
      self[:date] = date
    end

    o.on('--remove ID', 'Remove a record.') do |id|
      self[:remove] = id
    end
    
    o.on('--update ID', 'Update a record.') do |id|
      self[:update] = id
    end

    o.on('--track ID', 'Track a record.') do |id|
      self[:track] = id
    end
    
    o.on_tail('-h', '--help', 'Display this help and exit') do
      puts @opts
      exit
    end        

  end

  begin
    @opts.parse!(args)
  rescue OptionParser::InvalidOption => e
    self[:invalid_argument] = e.message
  end
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



4
5
6
# File 'lib/timekeeper/keeper_options.rb', line 4

def opts
  @opts
end