Class: Vkit::CLI::Commands::RegistryDiffCommand

Inherits:
BaseCommand
  • Object
show all
Defined in:
lib/vkit/cli/commands/registry_diff_command.rb

Constant Summary collapse

DEFAULT_PATH =
File.join("datasets", "registry.yaml")

Instance Method Summary collapse

Instance Method Details

#call(dir:, format: "human") ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/vkit/cli/commands/registry_diff_command.rb', line 14

def call(dir:, format: "human")
  ensure_project!(dir)

  dir  = File.expand_path(dir)
  path = File.join(dir, DEFAULT_PATH)

  unless File.exist?(path)
    puts "❌ No local registry.yaml found."
    exit 2
  end

  with_auth do
    user = credential_store.user
    org  = user["organization_slug"]

    local = YAML.safe_load(
      File.read(path),
      permitted_classes: [],
      permitted_symbols: [],
      aliases: false
    )
    runtime = authenticated_client.get(
      "/api/v1/orgs/#{org}/registries/export"
    )

    diff = Vkit::Core::RegistryDiff.compute(
      local: local,
      remote: runtime
    )

    if format == "json"
      puts JSON.pretty_generate(diff)
      exit diff["datasets"].empty? ? 0 : 1
    else
      Vkit::Core::RegistryDiffPrinter.print(diff)
      exit diff["datasets"].empty? ? 0 : 1
    end
  end

rescue StandardError => e
  puts "❌ Error: #{e.message}"
  exit 2
end