Class: Zold::Push

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

Overview

Wallet pushing command

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Push.



37
38
39
40
41
# File 'lib/zold/commands/push.rb', line 37

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

Instance Method Details

#run(args = []) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/zold/commands/push.rb', line 43

def run(args = [])
  opts = Slop.parse(args, help: true, suppress_errors: true) do |o|
    o.banner = "Usage: zold push [ID...] [options]
Available options:"
    o.bool '--sync',
      'Wait until the server confirms merge and pushes all wallets further (default: false)',
      default: false
    o.bool '--help', 'Print instructions'
  end
  mine = Args.new(opts, @log).take || return
  mine = @wallets.all if mine.empty?
  mine.each do |id|
    wallet = @wallets.find(Id.new(id))
    raise "The wallet #{id} is absent" unless wallet.exists?
    push(wallet, opts)
  end
end