#!/usr/bin/env ruby require 'burglar' require 'mercenary' require 'cymbal' require 'yaml' require 'date' def add_common_opts(c) c.option :config, '-c FILE', '--config FILE', 'Config file to load' c.option :begin, '-b DATE', '--begin DATE', 'Beginning of date range' c.option :end, '-e DATE', '--end DATE', 'End of date range' end def load_config(file) file ||= '~/.burglar.yml' file = File.expand_path file Cymbal.symbolize YAML.safe_load(File.read(file)) end def date_parse_or_default(string, default) return default unless string Date.parse(string) end Mercenary.program(:burglar) do |p| p.version Burglar::VERSION p.description 'Load data from banks' p.syntax 'burglar [options]' add_common_opts(p) p.action do |_, options| options[:end] = date_parse_or_default(options[:end], Date.today) options[:begin] = date_parse_or_default(options[:begin], options[:end]) config = load_config(options[:config]).merge(options) puts Burglar.new(config).transactions end end