mirror of
https://github.com/zhigang1992/RubyMotion.git
synced 2026-04-22 11:46:10 +08:00
better rubixir command line tool
This commit is contained in:
92
bin/rubixir
92
bin/rubixir
@@ -1,41 +1,87 @@
|
||||
#!/usr/bin/ruby
|
||||
|
||||
if ARGV.size != 1
|
||||
$stderr.puts "Usage: #{File.basename(__FILE__)} <app-name>"
|
||||
exit 1
|
||||
end
|
||||
require 'optparse'
|
||||
|
||||
app_name = ARGV[0]
|
||||
class RubixirCommandLine
|
||||
def initialize(argv)
|
||||
@argv = argv
|
||||
OptionParser.new do |opts|
|
||||
opts.banner = "Usage: #{File.basename(__FILE__)} [options] <args...>"
|
||||
|
||||
opts.on('--update', 'Updates installation') { @mode = :update }
|
||||
opts.on('--irb', 'Starts interactive prompt') { @mode = :irb }
|
||||
opts.on('--create <app-name>', 'Creates new project') { |app_name| @mode = :create; @app_name = app_name }
|
||||
opts.on('--help', 'Display this message') { die opts }
|
||||
|
||||
begin
|
||||
opts.parse!(@argv)
|
||||
rescue OptionParser::InvalidOption => e
|
||||
die e, opts
|
||||
end
|
||||
die opts unless @mode
|
||||
end
|
||||
end
|
||||
|
||||
unless app_name.match(/^[a-zA-Z\d\s]+$/)
|
||||
$stderr.puts "Invalid app name"
|
||||
exit 1
|
||||
end
|
||||
def run
|
||||
case @mode
|
||||
when :create
|
||||
create_project
|
||||
when :irb
|
||||
start_irb
|
||||
when :update
|
||||
update_installation
|
||||
else
|
||||
die "unknown mode"
|
||||
end
|
||||
end
|
||||
|
||||
if File.exist?(app_name)
|
||||
$stderr.puts "Directory `#{app_name}' already exists"
|
||||
exit 1
|
||||
end
|
||||
private
|
||||
|
||||
Dir.mkdir(app_name)
|
||||
Dir.chdir(app_name) do
|
||||
File.open('Rakefile', 'w') do |io|
|
||||
io.puts <<EOS
|
||||
def create_project
|
||||
unless @app_name.match(/^[a-zA-Z\d\s]+$/)
|
||||
$stderr.puts "Invalid app name"
|
||||
exit 1
|
||||
end
|
||||
|
||||
if File.exist?(@app_name)
|
||||
$stderr.puts "Directory `#{@app_name}' already exists"
|
||||
exit 1
|
||||
end
|
||||
|
||||
Dir.mkdir(@app_name)
|
||||
Dir.chdir(@app_name) do
|
||||
File.open('Rakefile', 'w') do |io|
|
||||
io.puts <<EOS
|
||||
require 'rubygems'
|
||||
require 'rubixir/rake'
|
||||
|
||||
Rubixir::CONFIG.app_name = '#{app_name}'
|
||||
Rubixir::CONFIG.app_name = '#{@app_name}'
|
||||
EOS
|
||||
end
|
||||
Dir.mkdir('app')
|
||||
File.open('app/main.rb', 'w') do |io|
|
||||
io.puts <<EOS
|
||||
end
|
||||
Dir.mkdir('app')
|
||||
File.open('app/main.rb', 'w') do |io|
|
||||
io.puts <<EOS
|
||||
class AppDelegate
|
||||
def application(application, didFinishLaunchingWithOptions:launchOptions)
|
||||
puts "Hello World!"
|
||||
end
|
||||
end
|
||||
EOS
|
||||
end
|
||||
Dir.mkdir('resources')
|
||||
end
|
||||
end
|
||||
|
||||
def start_irb
|
||||
end
|
||||
|
||||
def update_installation
|
||||
end
|
||||
|
||||
def die(*args)
|
||||
$stderr.puts *args
|
||||
exit 1
|
||||
end
|
||||
Dir.mkdir('resources')
|
||||
end
|
||||
|
||||
RubixirCommandLine.new(ARGV).run
|
||||
|
||||
Reference in New Issue
Block a user