#!/usr/bin/env ruby require 'optparse' begin require 'js2bookmarklet' rescue LoadError => e puts "Error: The js2bookmarklet gem is required" exit 1 end options = {} input_file = ARGV.last output_file = nil usage = "Usage: js2bookmarklet [options] [input file]" OptionParser.new do |opts| opts.banner = usage opts.on("-o [file name]", "--output [file name]", "Output file") do |o| output_file = o end opts.on("-a [text]", "--link-text [text]", "Link text") do |t| options["text"] = t end opts.on("-t [title]", "--link-title [title]", "Link title") do |t| options["title"] = t end end.parse! if File.exists?(input_file.to_s) input = open(input_file).read output = Js2bookmarklet.new(input, options).to_bookmarklet if output_file open(output_file, "w").write(output) else puts output end else puts usage puts "Error: Input file does not exist" exit 1 end