From 7fd0a464821aa9ad9ef0d5a16d0bedecdf83c542 Mon Sep 17 00:00:00 2001 From: Katharina Fey Date: Sun, 4 Aug 2019 02:21:22 +0200 Subject: First functional version Has a few problems: - Doesn't properly indent entries - Only processes _first_ open account - Doesn't catch enough errors - CLI parsing sucks --- cass.rb | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 cass.rb (limited to 'cass.rb') diff --git a/cass.rb b/cass.rb new file mode 100755 index 0000000..7c8abbf --- /dev/null +++ b/cass.rb @@ -0,0 +1,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 " + + 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 -- cgit v1.2.3