Class: Ramaze::Bin::Create

Inherits:
Object
  • Object
show all
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

Author:

  • Yorick Peterse

Since:

  • 21-07-2011

Constant Summary collapse

Description =

Since:

  • 21-07-2011

'Creates a new Ramaze application'
<<-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

Constructor Details

#initializeCreate

Creates a new instance of the command and sets the options for OptionParser.

Author:

  • Yorick Peterse

Since:

  • 21-07-2011



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         = 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.

Parameters:

  • argv (Array) (defaults to: [])

    Array containing all command line arguments.

Author:

  • Yorick Peterse

Since:

  • 21-07-2011



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