Sha256: 903c3d1e2abac6433a6b5bbd4a8205fabc510de8d23a7dae4cff93154ee32bef

Contents?: true

Size: 1.23 KB

Versions: 4

Compression:

Stored size: 1.23 KB

Contents

#!/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'
  c.option :shell, '-s', '--shell', 'Launch a REPL with the burglar object'
end

def date_parse_or_default(string, default)
  return default unless string
  Date.parse(string)
end

def launch_shell(res)
  res.transactions
  require 'pry'
  binding.pry # rubocop:disable Lint/Debugger
rescue LoadError
  warn 'Falling back to IRB because Pry failed to load'
  require 'irb'
  binding.irb # rubocop:disable Lint/Debugger
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)
    res = Burglar.new(options)
    if options[:shell]
      launch_shell res
    else
      puts res.transactions
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
burglar-0.3.2 bin/burglar
burglar-0.3.1 bin/burglar
burglar-0.3.0 bin/burglar
burglar-0.2.0 bin/burglar