Class: RubynCode::CLI::Commands::Export
- 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
-
#execute(args, ctx) ⇒ Object
-- CLI arg parsing is intrinsically procedural.
Methods inherited from Base
Class Method Details
.command_name ⇒ Object
15 |
# File 'lib/rubyn_code/cli/commands/export.rb', line 15 def self.command_name = '/export' |
.description ⇒ Object
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 = ctx.conversation.to_a if .empty? ctx.renderer.warning('No messages to export.') return end path = File.(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() : render_markdown() File.write(path, body) plural = .size == 1 ? '' : 's' ctx.renderer.info("Exported #{.size} message#{plural} to #{path}") end |