Sha256: 7df49ae540dd8dbc6d3da7991b7df55eeca49ae133d2638491271855ad2cb054

Contents?: true

Size: 1.13 KB

Versions: 3

Compression:

Stored size: 1.13 KB

Contents

#!/usr/bin/env ruby

require 'bundler/setup'
require 'svgcode'
require 'thor'


class SVGCLI < Thor
  desc 'parse SVG_PATH [--out OUT_PATH] [--comments]',
    'parses an SVG file to a G-code file'
  option :out_path
  option :comments, type: :boolean
  long_desc <<-LONGDESC
    `svgcode parse ~/Desktop/img.svg` will save the G-code file as 
    '~/Desktop/img.ngc'.

    Optionally set the --out-path flag to save the G-code file elsewhere
    \x5 e.g. `svgcode parse ~/Documents/img.svg --out-path ~/Desktop/gcode.nc`

    Optionally pass the --comments flag to print SVG IDs as comments
    \x5 e.g. `svgcode parse --comments ~/Desktop/img.svg`
  LONGDESC
  def parse(in_path)
    in_path = File.expand_path(in_path)
    raise "#{in_path} is not readable" unless File.readable?(in_path)
    svg_str = File.read(in_path)

    out_path =
    if options[:out_path].nil?
      in_path.gsub(/\.svg\Z/i, '.ngc')
    else
      File.expand_path(options[:out_path])
    end

    opts = { comments: options[:comments] }
    File.open(out_path, 'w') { |f| f << Svgcode.parse(svg_str, opts) }

    puts "G-code written to #{out_path}"
  end
end


SVGCLI.start(ARGV)

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
svgcode-0.4.0 bin/svgcode
svgcode-0.3.0 bin/svgcode
svgcode-0.2.0 bin/svgcode