Class: Shadwire::Commands::Diff

Inherits:
Object
  • Object
show all
Defined in:
lib/shadwire/commands/diff.rb

Overview

Reports how installed files have drifted from the registry: for each file of each requested (or, with no names, every installed) item, compares the local bytes to the freshly fetched registry content. Status per file is "unchanged", "modified", or "missing". Read-only — never writes.

Instance Method Summary collapse

Constructor Details

#initialize(root:, names: [], registry: nil, json: false, ui: UI.new) ⇒ Diff

Returns a new instance of Diff.



12
13
14
15
16
17
18
# File 'lib/shadwire/commands/diff.rb', line 12

def initialize(root:, names: [], registry: nil, json: false, ui: UI.new)
  @root = root.to_s
  @names = names
  @registry_override = registry
  @json = json
  @ui = ui
end

Instance Method Details

#callObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/shadwire/commands/diff.rb', line 20

def call
  config = Config.load(@root)
  client = RegistryClient.new(@registry_override || config.registry)

  entries = []
  diffs = {}
  resolve_names(config).each do |name|
    client.item(name).fetch("files").each do |file|
      target = file["target"]
      status, rendered = compare(target, file["content"])
      entries << { name:, file: target, status: }
      diffs["#{name}:#{target}"] = rendered if status == "modified"
    end
  end

  drifted = entries.any? { |entry| entry[:status] != "unchanged" }
  emit(entries, diffs)
  { entries:, diffs:, drifted: }
end