#!/usr/bin/env ruby require 'burglar' require 'mercenary' 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' c.option :pending, '-p', '--pending', 'Include pending transactions' 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] - 30) puts Burglar.new(config).transactions end end