Class: Ramaze::Bin::Create
- Inherits:
-
Object
- Object
- Ramaze::Bin::Create
- Defined in:
- lib/ramaze/bin/create.rb
Overview
Simple command that allows users to easily create a new application based on the prototype that ships with Ramaze.
Usage:
ramaze create blog
Constant Summary collapse
- Description =
'Creates a new Ramaze application'
- Banner =
<<-TXT.strip Allows developers to easily create new Ramaze applications based on the prototype that ships with Ramaze. Usage: ramaze create [NAME] [OPTIONS] Example: ramaze create blog TXT
Instance Method Summary collapse
-
#initialize ⇒ Create
constructor
Creates a new instance of the command and sets the options for OptionParser.
-
#run(argv = []) ⇒ Object
Runs the command based on the specified command line arguments.
Constructor Details
#initialize ⇒ Create
Creates a new instance of the command and sets the options for OptionParser.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ramaze/bin/create.rb', line 38 def initialize @options = { :force => false } @opts = OptionParser.new do |opt| opt. = Banner opt.summary_indent = ' ' opt.separator "\nOptions:\n" opt.on('-f', '--force', 'Overwrites existing directories') do @options[:force] = true end opt.on('-h', '--help', 'Shows this help message') do puts @opts exit end end end |
Instance Method Details
#run(argv = []) ⇒ Object
Runs the command based on the specified command line arguments.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/ramaze/bin/create.rb', line 67 def run(argv = []) @opts.parse!(argv) path = argv.delete_at(0) proto = __DIR__('../../proto') abort 'You need to specify a name for your application' if path.nil? if File.directory?(path) and @options[:force] === false abort 'The specified application already exists, use -f to overwrite it' end if File.directory?(path) and @options[:force] === true FileUtils.rm_rf(path) end begin FileUtils.cp_r(proto, path) puts "The application has been generated and saved in #{path}" rescue abort 'The application could not be generated' end end |