Class: Arcanus::Command::Diff

Inherits:
Base
  • Object
show all
Includes:
Shared::EnsureKey
Defined in:
lib/arcanus/command/diff.rb

Instance Method Summary collapse

Methods included from Shared::EnsureKey

#ensure_key_unlocked

Methods inherited from Base

description, #execute_command, from_arguments, #initialize, #run, short_name

Methods included from Utils

camel_case, deep_dup, snake_case

Constructor Details

This class inherits a constructor from Arcanus::Command::Base

Instance Method Details

#executeObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/arcanus/command/diff.rb', line 11

def execute
  ensure_key_unlocked

  ref = arguments[1] || 'HEAD'

  tempfile = ::Tempfile.new(['old-arcanus-chest', '.yaml']).tap do |file|
    # This will gracefully return an empty string if it doesn't exist
    old_content = `git show #{ref}:#{Arcanus::CHEST_FILE_PATH} 2>/dev/null`.strip

    file.sync = true
    if old_content.empty?
      file.write({}.to_yaml)
    else
      file.write(old_content)
    end
  end

  key = Arcanus::Key.from_file(repo.unlocked_key_path)
  old = Arcanus::Chest.new(key: key, chest_file_path: tempfile).to_yaml
  current = Arcanus::Chest.new(key: key, chest_file_path: repo.chest_file_path).to_yaml

  ui.print(::Diffy::Diff.new(old, current, context: 1).to_s(:color), newline: false)
end