Class: Bones::App::Create
Constant Summary
Constants inherited
from Command
Bones::App::Command::DEFAULT_SKELETON
Constants included
from Colors
Colors::COLORS
Instance Attribute Summary
Attributes inherited from Command
#config, #stderr, #stdout
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Command
#in_directory, inherited, #initialize, #mrbones_dir, #name, #output_dir, #repository, #skeleton_dir, #standard_options, standard_options, #verbose?
Methods included from Colors
#colorize, #colorize?
Class Method Details
.in_output_directory(*args) ⇒ Object
23
24
25
26
27
|
# File 'lib/bones/app/create.rb', line 23
def self.in_output_directory( *args )
@in_output_directory ||= []
@in_output_directory.concat(args.map {|str| str.to_sym})
@in_output_directory
end
|
.initialize_create ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/bones/app/create.rb', line 5
def self.initialize_create
synopsis 'bones create [options] <project_name>'
summary 'create a new project from a skeleton'
description <<-__
Create a new project from a Mr Bones project skeleton. The skeleton can
be the default project skeleton from the Mr Bones gem or one of the named
skeletons found in the '~/.mrbones/' folder. A git or svn repository can
be used as the skeleton if the '--repository' flag is given.
__
option(standard_options[:directory])
option(standard_options[:skeleton])
option(standard_options[:repository])
option(standard_options[:colorize])
end
|
Instance Method Details
76
77
78
79
80
|
# File 'lib/bones/app/create.rb', line 76
def announce
msg = "Created '#{name}'"
msg << " in directory '#{output_dir}'" if name != output_dir
stdout.puts msg
end
|
#copy_files ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/bones/app/create.rb', line 53
def copy_files
fm = FileManager.new(
:source => repository || skeleton_dir,
:destination => output_dir,
:stdout => stdout,
:stderr => stderr,
:verbose => true
)
fm.template name
rescue Bones::App::FileManager::Error => err
FileUtils.rm_rf output_dir
msg = "Could not create '#{name}'"
msg << " in directory '#{output_dir}'" if name != output_dir
msg << "\n#{err.message}"
raise Error, msg
rescue Exception => err
FileUtils.rm_rf output_dir
msg = "Could not create '#{name}'"
msg << " in directory '#{output_dir}'" if name != output_dir
msg << "\n#{err.inspect}"
raise Error, msg
end
|
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/bones/app/create.rb', line 82
def fixme
return unless test ?f, 'Rakefile'
tasks = %x{#{::Bones::RUBY} -S rake -T}
return unless tasks =~ %r/^(rake )?notes/m
stdout.puts
stdout.puts colorize('-'*31, :yellow)
stdout.puts 'Now you need to fix these files'
stdout.puts colorize('-'*31, :yellow)
system "#{::Bones::RUBY} -S rake notes"
end
|
#parse(args) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/bones/app/create.rb', line 41
def parse( args )
opts = super args
config[:name] = args.empty? ? nil : args.join('_')
config[:output_dir] = name if output_dir.nil?
if name.nil?
stdout.puts opts
exit 1
end
end
|
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/bones/app/create.rb', line 29
def run
raise Error, "Output directory #{output_dir.inspect} already exists." if test ?e, output_dir
copy_files
announce
in_directory(output_dir) {
self.class.in_output_directory.each {|cmd| self.send cmd}
fixme
}
end
|