bin/burglar in burglar-0.0.2 vs bin/burglar in burglar-0.0.3

- old
+ new

@@ -2,10 +2,11 @@ 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' @@ -15,19 +16,24 @@ 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.today - options[:begin] ||= options[:end] - 30 + 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