Files
RubyMotion/lib/motion/command/create.rb
Eloy Durán fea2150aae [Command] Deprecate Motion::Project::Command, long live Motion::Command!
Some of our commands are not related to ‘a project’ at all, so the
namespacing felt incorrect, but this also helps greatly for the
transition process. I.e. old command plugins will inherit from the
deprecated class and still work and we get to re-use the `Command` name.
2014-01-20 17:56:14 +01:00

73 lines
2.5 KiB
Ruby

# Copyright (c) 2012, HipByte SPRL and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
require 'motion/project/app'
require 'motion/project/template'
module Motion; class Command
class Create < Command
DefaultTemplate = 'ios'
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
end
def run
Motion::Project::App.create(@app_name, @template)
end
end
end; end