Files
RubyMotion/bin/motion
Laurent Sansonetti 4c901d71e2 forgot to return true
2011-11-05 13:42:23 +01:00

110 lines
2.4 KiB
Ruby

#!/usr/bin/ruby
$motion_libdir = File.expand_path(File.join(File.dirname(File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__), '../lib'))
$:.unshift($motion_libdir)
require 'motion/version'
class Command
class << self
attr_accessor :name
attr_accessor :help
end
end
class CreateCommand < Command
self.name = 'create'
self.help = 'Create a new project'
def self.run(args)
if args.size != 1
$stderr.puts "Please specify an app name (e.g. motion create Hello)"
return false
end
app_name = args.shift
unless app_name.match(/^[a-zA-Z\d\s]+$/)
$stderr.puts "Invalid app name"
return false
end
if File.exist?(app_name)
$stderr.puts "Directory `#{app_name}' already exists"
return false
end
Dir.mkdir(app_name)
Dir.chdir(app_name) do
File.open('Rakefile', 'w') do |io|
io.puts <<EOS
$:.unshift(\"#{$motion_libdir}\")
require 'motion/rake'
Motion::App.setup do |app|
# Use `rake config' to see complete project settings.
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!"
return true
end
end
EOS
end
Dir.mkdir('resources')
end
end
end
class UpdateCommand < Command
self.name = 'update'
self.help = 'Update current distribution'
def self.run(args)
$stderr.puts "update command not implemented yet"
return false
end
end
class MotionMainCommand
Commands = [CreateCommand, UpdateCommand]
def initialize(args)
arg = args.shift
case arg
when '-h', '--help'
usage
when '-v', '--version'
$stdout.puts Motion::Version
exit 1
when /^-/
$stderr.puts "Unknown option: #{arg}"
exit 1
end
command = Commands.find { |command| command.name == arg }
usage unless command
exit command.run(args) ? 0 : 1
end
def usage
$stderr.puts 'Usage:'
$stderr.puts " #{File.basename(__FILE__)} [-h, --help]"
$stderr.puts " #{File.basename(__FILE__)} [-v, --version]"
$stderr.puts " #{File.basename(__FILE__)} <command> [<args...>]"
$stderr.puts ''
$stderr.puts 'Commands:'
Commands.each do |command|
$stderr.puts " #{command.name}".ljust(15) + command.help
end
exit 1
end
end
MotionMainCommand.new(ARGV)