Module: HCl::Commands
- Included in:
- App
- Defined in:
- lib/hcl/commands.rb
Instance Method Summary collapse
- #aliases ⇒ Object
- #note(*args) ⇒ Object
- #set(key = nil, *args) ⇒ Object
- #show(*args) ⇒ Object
- #start(*args) ⇒ Object
- #stop ⇒ Object
- #tasks ⇒ Object
- #unset(key) ⇒ Object
Instance Method Details
#aliases ⇒ Object
32 33 34 |
# File 'lib/hcl/commands.rb', line 32 def aliases @settings.keys.select { |s| s =~ /^task\./ }.map { |s| s.slice(5..-1) } end |
#note(*args) ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/hcl/commands.rb', line 67 def note *args = args.join ' ' entry = DayEntry.with_timer if entry entry.append_note puts "Added note '#{}' to #{entry}." else puts "No running timers found." end end |
#set(key = nil, *args) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/hcl/commands.rb', line 13 def set key = nil, *args if key.nil? @settings.each do |k, v| puts "#{k}: #{v}" end else value = args.join(' ') @settings ||= {} @settings[key] = value write_settings end nil end |
#show(*args) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/hcl/commands.rb', line 78 def show *args date = args.empty? ? nil : Chronic.parse(args.join(' ')) total_hours = 0.0 DayEntry.all(date).each do |day| running = day.running? ? '(running) ' : '' puts "\t#{day.formatted_hours}\t#{running}#{day.project} #{day.notes}"[0..78] total_hours = total_hours + day.hours.to_f end puts "\t" + '-' * 13 puts "\t#{as_hours total_hours}\ttotal" end |
#start(*args) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/hcl/commands.rb', line 36 def start *args starting_time = args.detect {|x| x =~ /^\+\d*(\.|:)?\d+$/ } if starting_time args.delete(starting_time) starting_time = time2float starting_time end ident = args.shift task_ids = if @settings.key? "task.#{ident}" @settings["task.#{ident}"].split(/\s+/) else [ident, args.shift] end task = Task.find *task_ids if task.nil? puts "Unknown project/task alias, try one of the following: #{aliases.join(', ')}." exit 1 end timer = task.start(:starting_time => starting_time, :note => args.join(' ')) puts "Started timer for #{timer}." end |
#stop ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/hcl/commands.rb', line 57 def stop entry = DayEntry.with_timer if entry entry.toggle puts "Stopped #{entry}." else puts "No running timers found." end end |
#tasks ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'lib/hcl/commands.rb', line 3 def tasks tasks = Task.all if tasks.empty? puts "No cached tasks. Run `hcl show' to populate the cache and try again." else tasks.each { |task| puts "#{task.project.id} #{task.id}\t#{task}" } end nil end |
#unset(key) ⇒ Object
27 28 29 30 |
# File 'lib/hcl/commands.rb', line 27 def unset key @settings.delete key write_settings end |