bin/puer in puer-0.0.1 vs bin/puer in puer-0.0.2
- old
+ new
@@ -1,8 +1,9 @@
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
+require 'rubygems'
require 'rubygems' unless defined?(Gem)
require 'thread'
class Object
alias sh system
@@ -12,5 +13,62 @@
unless $LOAD_PATH.include?(lib_dir)
$LOAD_PATH << lib_dir
end
require 'puer'
+require 'optparse'
+
+OptionParser.new do |opts|
+ opts.banner =<<END
+ Usage: puer [options] [filename]
+ Usage: puer all # convert all xib files to js under current directory
+END
+
+ opts.on("-w", "--[no-]warnings", "Show warnings") do |w|
+ @show_warnings = w
+ end
+
+ opts.on("-o", "--output-file name", "Specify output file") do |o|
+ @output_file = o
+ end
+
+ opts.on("-c", "--config-file name", "Specify config file") do |o|
+ @config_file = o
+ end
+
+end.parse!
+
+if ARGV.size == 1
+
+ case ARGV[0]
+ when "all"
+ Dir.glob(File.join('**','*.xib')).each do |s|
+ puts "#{s} is converted to #{File.basename(s, '.*')}.js "
+ system "puer #{s} -o #{File.basename(s, '.*')}.js"
+ exit
+ end
+ else
+ input_file = ARGV.first
+
+ session = Session.new @config_file || File.join("#{File.dirname(__FILE__)}/../lib/puer", 'config.rb')
+ session.parse_file input_file
+ if session.has_errors?
+ puts "Aborted!"
+ puts session.full_log [:error]
+ else
+ severities = []
+ severities.unshift :warning if @show_warnings
+ log = session.full_log severities
+ script = js_comments_for(log) + js_for(session.out)
+ if @output_file
+ File.open(@output_file, 'w') do |file|
+ file.write script
+ end
+ puts log
+ else
+ puts script
+ end
+ end
+ end
+else
+ puts "For help, type: puer -h"
+end
\ No newline at end of file