mirror of
https://github.com/zhigang1992/RubyMotion.git
synced 2026-06-12 17:19:01 +08:00
motion create usage will now print available templates
This commit is contained in:
committed by
Watson
parent
9b9daa2c85
commit
ed71b653c2
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user