#!/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 " 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