Files
RubyMotion/bin/rubixir
2011-10-24 23:48:52 +02:00

90 lines
1.8 KiB
Ruby

#!/usr/bin/ruby
require 'optparse'
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
def run
case @mode
when :create
create_project
when :irb
start_irb
when :update
update_installation
else
die "unknown mode"
end
end
private
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'
Motion::App.setup do |app|
app.name = '#{@app_name}'
end
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
end
RubixirCommandLine.new(ARGV).run