class Zold::Diff
DIFF pulling command
Public Class Methods
new(wallets:, copies:, log: Log::NULL)
click to toggle source
# File lib/zold/commands/diff.rb, line 42 def initialize(wallets:, copies:, log: Log::NULL) @wallets = wallets @copies = copies @log = log end
Public Instance Methods
run(args = [])
click to toggle source
# File lib/zold/commands/diff.rb, line 48 def run(args = []) opts = Slop.parse(args, help: true, suppress_errors: true) do |o| o.banner = "Usage: zold diff [ID...] [options] Available options:" o.bool '--help', 'Print instructions' end mine = Args.new(opts, @log).take || return raise 'At least one wallet ID is required' if mine.empty? stdout = '' mine.map { |i| Id.new(i) }.each do |id| stdout += diff(id, Copies.new(File.join(@copies, id)), opts) end stdout end
Private Instance Methods
diff(id, cps, _)
click to toggle source
# File lib/zold/commands/diff.rb, line 65 def diff(id, cps, _) raise "There are no remote copies, try 'zold fetch' first" if cps.all.empty? cps = cps.all.sort_by { |c| c[:score] }.reverse patch = Patch.new(@wallets, log: @log) cps.each do |c| patch.join(Wallet.new(c[:path])) end before = @wallets.acq(id) do |wallet| IO.read(wallet.path) end after = '' Tempfile.open(['', Wallet::EXT]) do |f| patch.save(f.path, overwrite: true) after = IO.read(f) end diff = Diffy::Diff.new(before, after, context: 0).to_s(:color) @log.info(diff) diff end