From 97c92ea1828184a03e1b05c3aeb2b8cda07d9bd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eloy=20Dur=C3=A1n?= Date: Fri, 17 Jan 2014 17:21:33 +0100 Subject: [PATCH] [command] Make `create` command work again. --- lib/motion/project/command.rb | 2 +- lib/motion/project/command/create.rb | 75 +++++++++++++++------------- lib/motion/project/template.rb | 1 + 3 files changed, 42 insertions(+), 36 deletions(-) diff --git a/lib/motion/project/command.rb b/lib/motion/project/command.rb index 414e6d73..57f8ec33 100644 --- a/lib/motion/project/command.rb +++ b/lib/motion/project/command.rb @@ -79,7 +79,7 @@ module Motion; module Project require 'motion/project/command/account' require 'motion/project/command/activate' require 'motion/project/command/changelog' - #require 'motion/project/command/create' + require 'motion/project/command/create' require 'motion/project/command/device_console' require 'motion/project/command/ri' require 'motion/project/command/support' diff --git a/lib/motion/project/command/create.rb b/lib/motion/project/command/create.rb index 51df7880..15e74a7d 100644 --- a/lib/motion/project/command/create.rb +++ b/lib/motion/project/command/create.rb @@ -25,43 +25,48 @@ require 'motion/project/app' require 'motion/project/template' module Motion; module Project - class CreateCommand < Command - self.name = 'create' - self.help = 'Create a new project' - + class Create < Command DefaultTemplate = 'ios' - - def run(args) - app_name = nil - template_name = DefaultTemplate - args.each do |a| - case a - when /--([^=]+)=(.+)/ - opt_name = $1.to_s.strip - opt_val = $2.to_s.strip - case opt_name - when 'template' - template_name = opt_val - else - die "Incorrect option `#{opt_name}'" - end - else - if app_name - app_name = nil - break - else - app_name = a - end - end + + def self.all_templates + Motion::Project::Template.all_templates.keys + end + + def self.templates_description + all_templates.map do |x| + x == DefaultTemplate ? "#{x} (default)" : x + end.join(', ') + end + + self.summary = 'Create a new project.' + + self.description = "Create a new RubyMotion project from one of the " \ + "following templates: #{templates_description}." + + self.arguments = 'APP-NAME' + + def self.options + [ + ['--template=NAME', "One of #{templates_description}."], + ].concat(super) + end + + def initialize(argv) + @template = argv.option('template') || DefaultTemplate + @app_name = argv.shift_argument + super + end + + def validate! + super + help! "A name for the new project is required." unless @app_name + unless self.class.all_templates.include?(@template) + help! "Invalid template specified `#{@template}'." end - - unless app_name - $stderr.puts "Usage: motion create [--template=] " - $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) + end + + def run + Motion::Project::App.create(@app_name, @template) end end end; end diff --git a/lib/motion/project/template.rb b/lib/motion/project/template.rb index 09d01f3f..cf1afc7e 100644 --- a/lib/motion/project/template.rb +++ b/lib/motion/project/template.rb @@ -22,6 +22,7 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. require 'erb' +require 'fileutils' module Motion; module Project class Template