Class: ClaudeMemory::Commands::ExportCommand

Inherits:
BaseCommand
  • Object
show all
Defined in:
lib/claude_memory/commands/export_command.rb

Overview

Exports facts, entities, and provenance to JSON for backup or migration. Output goes to stdout (default) or a file via –output.

Instance Attribute Summary

Attributes inherited from BaseCommand

#stderr, #stdin, #stdout

Instance Method Summary collapse

Methods inherited from BaseCommand

#initialize

Constructor Details

This class inherits a constructor from ClaudeMemory::Commands::BaseCommand

Instance Method Details

#call(args) ⇒ Object



10
11
12
13
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
# File 'lib/claude_memory/commands/export_command.rb', line 10

def call(args)
  opts = parse_options(args, {scope: "project", status: "active", output: nil, pretty: false}) do |o|
    OptionParser.new do |parser|
      parser.banner = "Usage: claude-memory export [options]"
      parser.on("--scope SCOPE", %w[all global project],
        "Scope: project (default), global, or all") { |v| o[:scope] = v }
      parser.on("--status STATUS", %w[active all],
        "Fact status: active (default) or all") { |v| o[:status] = v }
      parser.on("--output FILE", "Write to file instead of stdout") { |v| o[:output] = v }
      parser.on("--pretty", "Pretty-print JSON output") { o[:pretty] = true }
    end
  end
  return 1 if opts.nil?

  manager = ClaudeMemory::Store::StoreManager.new
  data = build_export(manager, opts[:scope], opts[:status])
  manager.close

  json = opts[:pretty] ? JSON.pretty_generate(data) : JSON.generate(data)

  if opts[:output]
    File.write(opts[:output], json)
    stderr.puts "Exported #{data[:facts].size} facts to #{opts[:output]}"
  else
    stdout.puts json
  end

  0
end