Class: Postsvg::CLI
- Inherits:
-
Thor
- Object
- Thor
- Postsvg::CLI
- Defined in:
- lib/postsvg/cli.rb
Overview
Command-line interface for postsvg
Instance Method Summary collapse
- #batch(input_dir, output_dir = nil) ⇒ Object
- #convert(input_path, output_path = nil) ⇒ Object
- #version ⇒ Object
Instance Method Details
#batch(input_dir, output_dir = nil) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/postsvg/cli.rb', line 59 def batch(input_dir, output_dir = nil) unless Dir.exist?(input_dir) say "Error: Input directory '#{input_dir}' not found", :red exit 1 end Dir.mkdir(output_dir) if output_dir && !Dir.exist?(output_dir) pattern = File.join(input_dir, "*.{ps,eps}") files = Dir.glob(pattern, File::FNM_CASEFOLD) if files.empty? say "No PS or EPS files found in #{input_dir}", :yellow return end say "Found #{files.size} file(s) to convert", :cyan files.each do |input_path| basename = File.basename(input_path, ".*") output_path = if output_dir File.join(output_dir, "#{basename}.svg") else File.join(input_dir, "#{basename}.svg") end begin ps_content = File.read(input_path) svg_output = Postsvg.convert(ps_content) File.write(output_path, svg_output) say " ✓ #{input_path} → #{output_path}", :green rescue Postsvg::Error => e say " ✗ #{input_path}: #{e.}", :red rescue StandardError => e say " ✗ #{input_path}: Unexpected error: #{e.}", :red end end end |
#convert(input_path, output_path = nil) ⇒ Object
20 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/postsvg/cli.rb', line 20 def convert(input_path, output_path = nil) unless File.exist?(input_path) say "Error: Input file '#{input_path}' not found", :red exit 1 end begin ps_content = File.read(input_path) svg_output = Postsvg.convert(ps_content) if output_path File.write(output_path, svg_output) say "Successfully converted #{input_path} to #{output_path}", :green else puts svg_output end rescue Postsvg::Error => e say "Conversion error: #{e.}", :red exit 1 rescue StandardError => e say "Unexpected error: #{e.}", :red say e.backtrace.join("\n"), :red if [:verbose] exit 1 end end |