open_module.rb (1370B)
1 #!/usr/bin/env ruby 2 3 require 'optparse' 4 5 options = { 6 skins: false 7 } 8 option_parser = OptionParser.new do |opts| 9 opts.banner = "Usage: #{$0} [options] [module slug, or any module .svg or source file]" 10 opts.on('--skins', 'Open the skin res-pp/ files along with everything else') do 11 options[:skins] = true 12 end 13 opts.on_tail('-h', '--help', 'Show this message') do 14 puts opts 15 exit 16 end 17 end 18 begin 19 option_parser.parse! 20 rescue => e 21 STDERR.puts e.to_s 22 STDERR.puts "\n" 23 STDERR.puts option_parser.help 24 exit 1 25 end 26 27 unless ARGV.size >= 1 28 STDERR.puts option_parser.help 29 exit 1 30 end 31 slug = ARGV[0] 32 unless slug =~ /^\w+$/ 33 if File.basename(slug) =~ /^(\w+)(-[\w-]+)?\.(svg|hpp|cpp)$/ 34 slug = $1 35 else 36 STDERR.puts "Invalid module slug or source file: #{slug}" 37 exit 38 end 39 end 40 41 def open(d, f) 42 afn = File.absolute_path(File.join(File.dirname($0), '..', d, f)) 43 if File.readable?(afn) 44 puts "Open #{File.join(d, f)}..." 45 out = `open #{afn}` 46 unless $?.success? 47 STDERR.puts "open failed:\n#{out}" 48 exit 1 49 end 50 end 51 end 52 53 open('res-src', "#{slug}-src.svg") 54 open('res-pp', "#{slug}-pp.svg") 55 if options[:skins] 56 Dir.glob(File.absolute_path(File.join(File.dirname($0), '..', 'res-pp', "#{slug}-*-pp.svg"))).each do |fn| 57 open('res-pp', File.basename(fn)) 58 end 59 end 60 open('src', "#{slug}.hpp") 61 open('src', "#{slug}.cpp")