# File lib/pry/commands/save_file.rb, line 49 def display_content output.puts @cc.content output.puts "\n\n--\nPlease use `--to FILE` to export to a file." output.puts "No file saved!\n--" end
# File lib/pry/commands/save_file.rb, line 38 def file_name opts[:to] || nil end
# File lib/pry/commands/save_file.rb, line 55 def mode opts.present?(:append) ? "a" : "w" end
# File lib/pry/commands/save_file.rb, line 20 def options(opt) CodeCollector.inject_options(opt) opt.on :to=, "Specify the output file path" opt.on :a, :append, "Append output to file" end
# File lib/pry/commands/save_file.rb, line 27 def process @cc = CodeCollector.new(args, opts, _pry_) raise CommandError, "Found no code to save." if @cc.content.empty? if !file_name display_content else save_file end end
# File lib/pry/commands/save_file.rb, line 42 def save_file File.open(file_name, mode) do |f| f.puts @cc.content end output.puts "#{file_name} successfully saved" end