Class: Dply::Cli::Setup
- Inherits:
-
Object
show all
- Includes:
- Logger
- Defined in:
- lib/dply/cli/setup.rb
Instance Method Summary
collapse
Methods included from Logger
#debug?, #logger, stderr, #stderr
Constructor Details
#initialize(argv) ⇒ Setup
Returns a new instance of Setup.
12
13
14
15
|
# File 'lib/dply/cli/setup.rb', line 12
def initialize(argv)
@argv = argv
@options = {}
end
|
Instance Method Details
#lock ⇒ Object
70
71
72
|
# File 'lib/dply/cli/setup.rb', line 70
def lock
@lock ||= ::Dply::Lock.new
end
|
#opts ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/dply/cli/setup.rb', line 74
def opts
OptionParser.new do |opts|
opts.banner = "Usage: drake setup [options] [namespace]"
opts.on("-h", "--help", "Help") do
puts opts
exit
end
end
end
|
#proceed? ⇒ Boolean
25
26
27
28
29
|
# File 'lib/dply/cli/setup.rb', line 25
def proceed?
print "Are you sure?(y/n) "
v = STDIN.gets.strip
v == "y"
end
|
#run ⇒ Object
17
18
19
20
21
22
23
|
# File 'lib/dply/cli/setup.rb', line 17
def run
opts.parse!(@argv)
return if not proceed?
lock.acquire
setup_default
setup_app_rake
end
|
#setup_app_rake ⇒ Object
56
57
58
59
60
61
62
63
64
|
# File 'lib/dply/cli/setup.rb', line 56
def setup_app_rake
tasks_file = "dply/app.rake"
if File.exist? tasks_file
logger.info "skipping #{tasks_file}"
return
end
FileUtils.cp "#{templates_dir}/deploy.erb", tasks_file
logger.info "created #{tasks_file}"
end
|
#setup_default ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/dply/cli/setup.rb', line 31
def setup_default
if not File.exist? "dply"
FileUtils.mkdir_p "dply"
logger.info "created dply/"
else
logger.info "skipping dply/"
end
rakefile = "dply/Rakefile"
if not File.exist? rakefile
FileUtils.touch rakefile
logger.info "created #{rakefile}"
else
logger.info "skipping #{rakefile}"
end
pkgs_yml = "pkgs.yml"
if not File.exist? pkgs_yml
FileUtils.cp "#{templates_dir}/pkgs.erb", pkgs_yml
logger.info "created #{pkgs_yml}"
else
logger.info "skipping #{pkgs_yml}"
end
end
|
#templates_dir ⇒ Object
66
67
68
|
# File 'lib/dply/cli/setup.rb', line 66
def templates_dir
@templates_dir ||= "#{__dir__}/../templates"
end
|