motion create usage will now print available templates

This commit is contained in:
Laurent Sansonetti
2013-05-04 20:04:06 +02:00
committed by Watson
parent 9b9daa2c85
commit ed71b653c2
2 changed files with 22 additions and 4 deletions

View File

@@ -22,15 +22,18 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
require 'motion/project/app'
require 'motion/project/template'
module Motion; module Project
class CreateCommand < Command
self.name = 'create'
self.help = 'Create a new project'
DefaultTemplate = 'ios'
def run(args)
app_name = nil
template_name = 'ios'
template_name = DefaultTemplate
args.each do |a|
case a
when /--([^=]+)=(.+)/
@@ -53,7 +56,9 @@ module Motion; module Project
end
unless app_name
die "Usage: motion create [--template=<template_name>] <app-name>"
$stderr.puts "Usage: motion create [--template=<template_name>] <app-name>"
$stderr.puts "Available templates: " + Motion::Project::Template.all_templates.keys.map { |x| x == DefaultTemplate ? "#{x} (default)" : x }.join(', ')
exit 1
end
Motion::Project::App.create(app_name, template_name)

View File

@@ -33,13 +33,26 @@ module Motion; module Project
File.expand_path(File.join(ENV['HOME'], 'Library/RubyMotion/template'))
]
def self.all_templates
@all_templates ||= begin
h = {}
Paths.map { |path| Dir.glob(path + '/*') }.flatten.select { |x| !x.match(/^\./) and File.directory?(x) }.each do |template_path|
h[File.basename(template_path)] = template_path
end
h
end
end
Templates = Paths.map { |path| Dir.glob(path + '/*') }.flatten.select { |x| !x.match(/^\./) and File.directory?(x) }.map { |x| File.basename(x) }
def initialize(app_name, template_name)
@name = @app_name = app_name
@template_name = template_name.to_s
@template_directory = Paths.map { |x| File.join(x, @template_name) }.find { |x| File.exist?(x) }
@template_directory = self.class.all_templates[@template_name]
unless @template_directory
$stderr.puts "Cannot find template `#{@template_name}' in #{Paths.join(' or ')}"
$stderr.puts "Available templates: " + self.class.all_templates.keys.join(', ')
exit 1
end