293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
|
# File 'lib/prompt_objects/cli/repl_command.rb', line 293
def run(args)
options = {
name: "greeter",
objects_dir: "objects",
sandbox: false
}
positional = []
args.each do |arg|
case arg
when "--sandbox", "-s"
options[:sandbox] = true
when "--help", "-h"
help
exit 0
else
positional << arg
end
end
options[:name] = positional[0] if positional[0]
options[:objects_dir] = positional[1] if positional[1]
sandbox = nil
primitives_dir = nil
if options[:sandbox]
sandbox = Sandbox.new(options[:objects_dir])
objects_dir = sandbox.objects_dir
primitives_dir = sandbox.primitives_dir
else
objects_dir = options[:objects_dir]
end
env = PromptObjects::Runtime.new(objects_dir: objects_dir, primitives_dir: primitives_dir)
begin
po = env.load_by_name(options[:name])
env.load_dependencies(po)
rescue PromptObjects::Error => e
puts "Error loading '#{options[:name]}': #{e.message}"
puts "\nAvailable objects in '#{objects_dir}/':"
Dir.glob(File.join(objects_dir, "*.md")).each do |path|
puts " - #{File.basename(path, '.md')}"
end
sandbox&.cleanup(keep_changes: false)
exit 1
end
REPL.new(po, env, sandbox: sandbox).run
end
|