#!/usr/bin/ruby $:.unshift(File.join(File.dirname(File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__), '../lib')) 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 motion_libdir = File.expand_path(File.join(__FILE__, '../../lib')) Dir.mkdir(app_name) Dir.chdir(app_name) do File.open('Rakefile', 'w') do |io| io.puts < []" $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)