Class: Timekeeper::ViewerOptions

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ ViewerOptions

Returns a new instance of ViewerOptions.



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
# File 'lib/timekeeper/viewer_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("--csv [FILE]", "export to csv") do |file|
      self[:output] = [(file || "timekeeper"), :csv]
    end        
    
    o.on('-n', '--name NAME', 'Query on name') do |name|
      self[:name] = name
    end        

    # o.on('-t', '--title TITLE', 'Query on title') do |title|
    #   self[:title] = title
    # end

    # o.on('-c', '--target TARGET', 'Query on target') do |target|
    #   self[:target] = target
    # end

    # o.on('-m', '--description DESCRIPTION', 'Query on description') do |description|
    #   self[:description] = description
    # end

    o.on('--month [month]', 'Query on month') do |month|
      self[:month] = month || Date.today.month
    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/viewer_options.rb', line 4

def opts
  @opts
end