Class: RubynCode::CLI::Commands::Export

Inherits:
Base
  • Object
show all
Defined in:
lib/rubyn_code/cli/commands/export.rb

Overview

Export the current conversation transcript to a file.

/export path/to/transcript.md              # markdown (default)
/export --format jsonl path/to/transcript.jsonl
/export path/to/transcript.md --force      # overwrite existing

Constant Summary collapse

MAX_LINE_LENGTH =
100

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

aliases, all_names, hidden?

Class Method Details

.command_nameObject



15
# File 'lib/rubyn_code/cli/commands/export.rb', line 15

def self.command_name = '/export'

.descriptionObject



16
# File 'lib/rubyn_code/cli/commands/export.rb', line 16

def self.description = 'Export conversation transcript to markdown or JSONL'

Instance Method Details

#execute(args, ctx) ⇒ Object

-- CLI arg parsing is intrinsically procedural



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rubyn_code/cli/commands/export.rb', line 21

def execute(args, ctx)
  opts = parse_args(args)
  return unless opts

  messages = ctx.conversation.to_a
  if messages.empty?
    ctx.renderer.warning('No messages to export.')
    return
  end

  path = File.expand_path(opts[:path])
  dir  = File.dirname(path)
  FileUtils.mkdir_p(dir) unless File.directory?(dir)

  if File.exist?(path) && !opts[:force] && !tty_yes?(ctx, "File exists at #{path}. Overwrite? [y/N]")
    ctx.renderer.info('Export cancelled.')
    return
  end

  body = opts[:format] == 'jsonl' ? render_jsonl(messages) : render_markdown(messages)
  File.write(path, body)
  plural = messages.size == 1 ? '' : 's'
  ctx.renderer.info("Exported #{messages.size} message#{plural} to #{path}")
end