Class: LocalVault::CLI::Guard

Inherits:
Thor
  • Object
show all
Defined in:
lib/localvault/cli/guard.rb

Instance Method Summary collapse

Instance Method Details

#hookObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/localvault/cli/guard.rb', line 16

def hook
  event = JSON.parse($stdin.read)
  result = LocalVault::Guard.evaluate(event)
  if result[:exit] != 0
    $stderr.puts result[:message]
    exit result[:exit]
  end
rescue StandardError
  # fail open
end

#installObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/localvault/cli/guard.rb', line 30

def install
  path = settings_path(options[:project])
  settings = File.exist?(path) ? JSON.parse(File.read(path)) : {}
  if LocalVault::Guard.merge_hooks!(settings)
    FileUtils.mkdir_p(File.dirname(path))
    File.write(path, JSON.pretty_generate(settings) + "\n")
    $stdout.puts "Installed LocalVault guard hooks in #{path}"
    $stdout.puts "Restart Claude Code sessions to pick up hook changes."
  else
    $stdout.puts "LocalVault guard hooks already installed in #{path}"
  end
  warn_if_path_binary_lacks_guard
rescue JSON::ParserError
  $stderr.puts "Error: #{path} is not valid JSON; fix it before installing."
end

#statusObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/localvault/cli/guard.rb', line 47

def status
  { "user" => settings_path(false), "project" => settings_path(true) }.each do |label, path|
    state = if !File.exist?(path)
      "not installed"
    else
      begin
        LocalVault::Guard.installed?(JSON.parse(File.read(path))) ? "installed" : "not installed"
      rescue JSON::ParserError
        "unreadable JSON"
      end
    end
    $stdout.puts "#{label} (#{path}): #{state}"
  end
end