Class: Zold::Taxes

Inherits:
Object
  • Object
show all
Defined in:
lib/zold/commands/taxes.rb

Overview

Taxes command

Instance Method Summary collapse

Constructor Details

#initialize(wallets:, remotes:, log: Log::Quiet.new) ⇒ Taxes

Returns a new instance of Taxes.


40
41
42
43
44
# File 'lib/zold/commands/taxes.rb', line 40

def initialize(wallets:, remotes:, log: Log::Quiet.new)
  @wallets = wallets
  @remotes = remotes
  @log = log
end

Instance Method Details

#run(args = []) ⇒ Object


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/zold/commands/taxes.rb', line 46

def run(args = [])
  opts = Slop.parse(args, help: true, suppress_errors: true) do |o|
    o.banner = "Usage: zold taxes command [options]
Available commands:
#{Rainbow('taxes pay').green} wallet
  Pay taxes for the given wallet
#{Rainbow('taxes show').green}
  Show taxes status for the given wallet
#{Rainbow('taxes debt').green}
  Show current debt
Available options:"
    o.string '--private-key',
      'The location of RSA private key (default: ~/.ssh/id_rsa)',
      require: true,
      default: '~/.ssh/id_rsa'
    o.bool '--help', 'Print instructions'
  end
  mine = Args.new(opts, @log).take || return
  command = mine[0]
  case command
  when 'show'
    raise 'At least one wallet ID is required' unless mine[1]
    mine[1..-1].each do |id|
      show(@wallets.find(Id.new(id)), opts)
    end
  when 'debt'
    raise 'At least one wallet ID is required' unless mine[1]
    mine[1..-1].each do |id|
      debt(@wallets.find(Id.new(id)), opts)
    end
  when 'pay'
    raise 'At least one wallet ID is required' unless mine[1]
    mine[1..-1].each do |id|
      pay(@wallets.find(Id.new(id)), opts)
    end
  else
    @log.info(opts.to_s)
  end
end