1
2
3
4
5
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
|
#!/usr/bin/env ruby
require "optparse"
require "pp"
require_relative "parser"
require_relative "time_util"
op = OptionParser.new
op.on("start ACCOUNT", String) do |acc|
puts acc
end
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: cassiopeia <command>"
opts.on("-f FILE", "--file=FILE", "Provide the working file") do |f|
options[:file] = f
end
opts.on("--start=ACCOUNT", "Start tracking time") do |acc|
options[:start] = acc
end
opts.on("--stop=ACCOUNT", "Stop working!") do |acc|
options[:stop] = acc
end
opts.on("-r", "--round", "Round to the next 15 minutes") do |r|
options[:round] = r
end
opts.on("-v", "--version", "Print program version") do |v|
puts "0.1.0"
end
end.parse!
path = options[:file]
start = options[:start]
stop = options[:stop]
round = !!options[:round]
file = File.open(path, "r") { |f| CassParser.new.parse(f.read) }
if start
require_relative "start"
new = start(start, round, file)
File.open(path, "a") { |f| f.write(new) }
elsif stop
require_relative "stop"
line, new = stop(stop, round, file)
lines = File.open(path, "r") { |f| f.readlines }
lines[line - 1] = new
File.open(path, "w") { |f| f.write(lines.join) }
end
|