#!/usr/bin/env ruby require 'ballista' require 'yaml' require 'mercenary' require 'cymbal' def parse_config(file) Cymbal.symbolize(YAML.load(File.read(file))) end Mercenary.program(:ballista) do |p| p.version Ballista::VERSION p.description 'Tool for projecting future activity with Ledger' p.syntax 'ballista [options] CONFIG_FILE' p.option :output, '-o FILE', '--output FILE', 'Output file for ledger' p.option :months, '-m INT', '--months INT', 'How far ahead to project' p.action do |_, options| config_file = ARGV.shift puts p unless config_file config = parse_config(config_file) months = options[:months].to_i || 12 projection = Ballista.new(entries: config).project(months) if options[:output] File.open(options[:output], 'w') { |fh| fh << projection.to_s } else puts projection end end end