Class: TogglCmd::RunnerOptions

Inherits:
Hash
  • Object
show all
Defined in:
lib/toggl_cmd/runner_options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ RunnerOptions

Returns a new instance of RunnerOptions.



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/toggl_cmd/runner_options.rb', line 6

def initialize(args)
  super()

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

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

    o.on('-p', '--project PROJECT', 'Who is going to pay?') do |project|
      self[:project] = project
    end

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

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

    o.on('--projects', 'Show projects') do |projects|
      self[:projects] = projects
    end
    
    o.on('-v', '--verbose', 'What\'s happening?') do |debug|
      self[:debug] = debug
    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/toggl_cmd/runner_options.rb', line 4

def opts
  @opts
end