mina 0.3.8 → 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +16 -0
  3. data/.gitignore +0 -1
  4. data/.rubocop.yml +1156 -0
  5. data/Gemfile +2 -8
  6. data/{CHANGELOG.md → PRE_1_CHANGELOG.md} +0 -0
  7. data/Rakefile +2 -18
  8. data/Readme.md +39 -1116
  9. data/bin/mina +1 -62
  10. data/data/deploy.rb +19 -46
  11. data/data/deploy.sh.erb +22 -23
  12. data/docs/Readme.md +8 -0
  13. data/docs/command_line_options.md +33 -0
  14. data/docs/deploying.md +97 -0
  15. data/docs/faq.md +1 -0
  16. data/docs/getting_started.md +44 -0
  17. data/docs/migrating.md +30 -0
  18. data/docs/writing_your_own_tasks.md +117 -0
  19. data/lib/Minafile +3 -0
  20. data/lib/mina.rb +30 -18
  21. data/lib/mina/application.rb +74 -0
  22. data/lib/mina/backend/local.rb +22 -0
  23. data/lib/mina/backend/remote.rb +42 -0
  24. data/lib/mina/commands.rb +45 -0
  25. data/lib/mina/configuration.rb +36 -0
  26. data/lib/mina/dsl.rb +47 -0
  27. data/lib/mina/helpers/internal.rb +29 -0
  28. data/lib/mina/helpers/output.rb +42 -0
  29. data/lib/mina/runner.rb +39 -0
  30. data/lib/mina/runner/exec.rb +15 -0
  31. data/lib/mina/runner/pretty.rb +53 -0
  32. data/lib/mina/runner/printer.rb +17 -0
  33. data/lib/mina/runner/system.rb +15 -0
  34. data/lib/mina/version.rb +1 -3
  35. data/mina.gemspec +27 -16
  36. data/spec/lib/mina/application_spec.rb +39 -0
  37. data/spec/lib/mina/backend/local_spec.rb +16 -0
  38. data/spec/lib/mina/backend/remote_spec.rb +17 -0
  39. data/spec/lib/mina/commands_spec.rb +93 -0
  40. data/spec/lib/mina/configuration_spec.rb +52 -0
  41. data/spec/lib/mina/helpers/internal_spec.rb +50 -0
  42. data/spec/lib/mina/helpers/output_spec.rb +48 -0
  43. data/spec/lib/mina/runner_spec.rb +36 -0
  44. data/spec/lib/mina_spec.rb +7 -0
  45. data/spec/spec_helper.rb +13 -21
  46. data/spec/support/run_helper.rb +36 -0
  47. data/tasks/mina/bundler.rb +15 -0
  48. data/tasks/mina/chruby.rb +19 -0
  49. data/tasks/mina/default.rb +36 -0
  50. data/tasks/mina/deploy.rb +85 -0
  51. data/tasks/mina/git.rb +36 -0
  52. data/tasks/mina/install.rb +18 -0
  53. data/tasks/mina/rails.rb +108 -0
  54. data/tasks/mina/rbenv.rb +15 -0
  55. data/tasks/mina/rvm.rb +39 -0
  56. data/tasks/mina/ry.rb +26 -0
  57. data/test_env/config/deploy.rb +44 -72
  58. metadata +82 -59
  59. data/.travis.yml +0 -21
  60. data/CONTRIBUTING.md +0 -124
  61. data/HISTORY.md +0 -394
  62. data/Makefile +0 -32
  63. data/Notes.md +0 -70
  64. data/lib/mina/bundler.rb +0 -49
  65. data/lib/mina/chruby.rb +0 -49
  66. data/lib/mina/default.rb +0 -158
  67. data/lib/mina/deploy.rb +0 -160
  68. data/lib/mina/deploy_helpers.rb +0 -34
  69. data/lib/mina/exec_helpers.rb +0 -111
  70. data/lib/mina/foreman.rb +0 -83
  71. data/lib/mina/git.rb +0 -69
  72. data/lib/mina/helpers.rb +0 -408
  73. data/lib/mina/local_helpers.rb +0 -97
  74. data/lib/mina/npm.rb +0 -89
  75. data/lib/mina/output_helpers.rb +0 -92
  76. data/lib/mina/rails.rb +0 -245
  77. data/lib/mina/rake.rb +0 -10
  78. data/lib/mina/rbenv.rb +0 -47
  79. data/lib/mina/rvm.rb +0 -88
  80. data/lib/mina/ry.rb +0 -55
  81. data/lib/mina/settings.rb +0 -32
  82. data/lib/mina/ssh_helpers.rb +0 -125
  83. data/lib/mina/tools.rb +0 -20
  84. data/lib/mina/whenever.rb +0 -51
  85. data/manual/index.md +0 -15
  86. data/manual/modules.md +0 -2
  87. data/spec/command_helper.rb +0 -52
  88. data/spec/commands/cleanup_spec.rb +0 -16
  89. data/spec/commands/command_spec.rb +0 -71
  90. data/spec/commands/custom_config_spec.rb +0 -20
  91. data/spec/commands/deploy_spec.rb +0 -40
  92. data/spec/commands/outside_project_spec.rb +0 -35
  93. data/spec/commands/real_deploy_spec.rb +0 -56
  94. data/spec/commands/ssh_spec.rb +0 -14
  95. data/spec/commands/verbose_spec.rb +0 -21
  96. data/spec/dsl/invoke_spec.rb +0 -49
  97. data/spec/dsl/queue_spec.rb +0 -49
  98. data/spec/dsl/settings_in_rake_spec.rb +0 -39
  99. data/spec/dsl/settings_spec.rb +0 -61
  100. data/spec/dsl/to_spec.rb +0 -20
  101. data/spec/fixtures/custom_file_env/custom_deploy.rb +0 -15
  102. data/spec/fixtures/empty_env/config/deploy.rb +0 -15
  103. data/spec/helpers/exec_helper_spec.rb +0 -19
  104. data/spec/helpers/local_helper_spec.rb +0 -70
  105. data/spec/helpers/output_helper_spec.rb +0 -38
  106. data/support/Readme-footer.md +0 -31
  107. data/support/Readme-header.md +0 -16
  108. data/support/guide.md +0 -297
  109. data/support/index.html +0 -53
  110. data/support/third_party_modules.md +0 -23
  111. data/support/to_md.rb +0 -11
@@ -1,34 +0,0 @@
1
- # # Helpers: Deploy helpers
2
- # Helpers for deployment.
3
- module Mina
4
- module DeployHelpers
5
- # ### deploy
6
- # Wraps the things inside it in a deploy script and queues it.
7
- # This generates a script using deploy_script and queues it.
8
- #
9
- # Returns nothing.
10
- #
11
- def deploy(&blk)
12
- queue deploy_script(&blk)
13
- end
14
-
15
- # ### deploy_script
16
- # Wraps the things inside it in a deploy script.
17
- #
18
- # script = deploy_script do
19
- # invoke :'git:checkout'
20
- # end
21
- #
22
- # queue script
23
- #
24
- # Returns the deploy script as a string, ready for `queue`ing.
25
- #
26
- def deploy_script(&blk)
27
- set_default :term_mode, :pretty
28
- code = isolate do
29
- yield
30
- erb Mina.root_path('data/deploy.sh.erb')
31
- end
32
- end
33
- end
34
- end
@@ -1,111 +0,0 @@
1
- # # Helpers: Exec helpers
2
- # Provides `pretty_system` which Mina uses to parse SSH output, and delegate to
3
- # the appropriate Output helper.
4
-
5
- module Mina
6
- module ExecHelpers
7
-
8
- # ### pretty_system
9
- # __Internal:__ A pretty version of the default `#system` commands, but
10
- # indents and puts color.
11
- #
12
- # Returns the exit code in integer form.
13
- #
14
- def pretty_system(code)
15
- require 'shellwords'
16
- cmds = Shellwords.shellsplit(code)
17
- coathooks = 0
18
-
19
- status =
20
- Tools.popen4(*cmds) do |pid, i, o, e|
21
- # Handle `^C`.
22
- trap("INT") { Sys.handle_sigint(coathooks += 1, pid, self) }
23
-
24
- # __In the background,__ make stdin passthru, and stream stderr.
25
- th_err = Sys.stream_stderr!(e) { |str| print_stderr str }
26
- th_in = Sys.stream_stdin! { |chr| i.putc chr }
27
-
28
- # __In the foreground,__ stream stdout to the output helper.
29
- Sys.stream_stdout(o) { |ch| print_char ch }
30
-
31
- th_err.join
32
- th_in.terminate
33
- end
34
-
35
- status.exitstatus
36
- end
37
-
38
- # ## Private methods
39
- # Delegate functions, mostly.
40
-
41
- module Sys
42
-
43
- extend self
44
-
45
- # ### Sys.handle_sigint!
46
- # Called when a `^C` is pressed. The param `count` is how many times it's
47
- # been pressed since. Returns nothing.
48
-
49
- def handle_sigint(count, pid, this)
50
- puts ""
51
- if count > 1
52
- this.print_status "Mina: SIGINT received again. Force quitting..."
53
- Process.kill "KILL", pid
54
- else
55
- this.print_status "Mina: SIGINT received."
56
- Process.kill "TERM", pid
57
- end
58
- end
59
-
60
- # ### Sys.stream_stderr!
61
- # __Internal:__ Read from stderr stream `err` *[0]*, supress expected
62
- # errors *[1]*, and yield. Returns the thread.
63
-
64
- def stream_stderr!(err, &blk)
65
- Thread.new do
66
- begin
67
- while str = err.gets #[0]
68
- next if str.include? "bash: no job control in this shell" #[1]
69
- next if str.include? "stdin is not a terminal"
70
-
71
- yield str.strip #[2]
72
- end
73
- rescue Interrupt
74
- end
75
- end
76
- end
77
-
78
- # ### Sys.stream_stdin!
79
- # __Internal:__ Read from the real stdin stream and pass it onto the given
80
- # stdin stream `i`. Returns the thread.
81
-
82
- def stream_stdin!(&blk)
83
- Thread.new do
84
- begin
85
- while (char = STDIN.getbyte rescue nil)
86
- yield char if char
87
- end
88
- rescue Interrupt
89
- # rubinius
90
- rescue SignalException
91
- end
92
- end
93
- end
94
-
95
- # ### Sys.stream_stdout
96
- # __Internal:__ Read from given stdout stream `o` and delegate it to the
97
- # output helper.
98
-
99
- def stream_stdout(o, &blk)
100
- while str = o.getc
101
- # Ruby 1.8.7 fix
102
- str = str.chr if str.is_a? Fixnum
103
-
104
- yield str
105
- end
106
- end
107
-
108
- end
109
-
110
- end
111
- end
data/lib/mina/foreman.rb DELETED
@@ -1,83 +0,0 @@
1
- # # Modules: Foreman
2
- # Adds settings and tasks for managing projects with [foreman].
3
- #
4
- # NOTE: Requires sudo privileges
5
- #
6
- # [foreman]: http://rubygems.org/ddolar/foreman
7
- #
8
- # require 'mina/foreman'
9
- #
10
- # ## Common usage
11
- #
12
- # set :application, "app-name"
13
- #
14
- # task :deploy => :environment do
15
- # deploy do
16
- # # ...
17
- # invoke 'foreman:export'
18
- # # ...
19
- # end
20
- #
21
- # to :launch do
22
- # invoke 'foreman:restart'
23
- # end
24
- # end
25
- #
26
-
27
- # ## Settings
28
- # Any and all of these settings can be overriden in your `deploy.rb`.
29
-
30
- # ### foreman_app
31
- # Sets the service name that foreman will export to upstart. Uses *application*
32
- # variable as a default. It should be set, otherwise export command will fail.
33
-
34
- # ### foreman_user
35
- # Sets the user under which foreman will execute the service. Defaults to *user*
36
-
37
- # ### foreman_log
38
- # Sets the foreman log path. Defaults to *shared/log*
39
-
40
- set_default :foreman_app, lambda { application }
41
- set_default :foreman_user, lambda { user }
42
- set_default :foreman_log, lambda { "#{deploy_to!}/#{shared_path}/log" }
43
- set_default :foreman_sudo, true
44
- set_default :foreman_format, 'upstart'
45
- set_default :foreman_location, '/etc/init'
46
- set_default :foreman_procfile, 'Procfile'
47
-
48
- namespace :foreman do
49
- desc 'Export the Procfile to Ubuntu upstart scripts'
50
- task :export do
51
- sudo_cmd = "sudo" if foreman_sudo
52
- export_cmd = "#{sudo_cmd} bundle exec foreman export #{foreman_format} #{foreman_location} -a #{foreman_app} -u #{foreman_user} -d #{deploy_to!}/#{current_path!} -l #{foreman_log} -f #{foreman_procfile}"
53
-
54
- queue %{
55
- echo "-----> Exporting foreman procfile for #{foreman_app}"
56
- #{echo_cmd %[cd #{deploy_to!}/#{current_path!} ; #{export_cmd}]}
57
- }
58
- end
59
-
60
- desc "Start the application services"
61
- task :start do
62
- queue %{
63
- echo "-----> Starting #{foreman_app} services"
64
- #{echo_cmd %[sudo start #{foreman_app}]}
65
- }
66
- end
67
-
68
- desc "Stop the application services"
69
- task :stop do
70
- queue %{
71
- echo "-----> Stopping #{foreman_app} services"
72
- #{echo_cmd %[sudo stop #{foreman_app}]}
73
- }
74
- end
75
-
76
- desc "Restart the application services"
77
- task :restart do
78
- queue %{
79
- echo "-----> Restarting #{foreman_app} services"
80
- #{echo_cmd %[sudo start #{foreman_app} || sudo restart #{foreman_app}]}
81
- }
82
- end
83
- end
data/lib/mina/git.rb DELETED
@@ -1,69 +0,0 @@
1
- # encoding: utf-8
2
-
3
- # # Modules: Git
4
- # Adds settings and tasks related to managing Git.
5
- #
6
- # require 'mina/git'
7
-
8
- # ## Settings
9
- # Any and all of these settings can be overriden in your `deploy.rb`.
10
-
11
- # ### branch
12
- # Sets the branch to be deployed.
13
-
14
- set_default :branch, 'master'
15
-
16
- namespace :git do
17
- # ## Deploy tasks
18
- # These tasks are meant to be invoked inside deploy scripts, not invoked on
19
- # their own.
20
-
21
- # ### git:clone
22
- # Clones the Git repository. Meant to be used inside a deploy script.
23
-
24
- desc "Clones the Git repository to the release path."
25
- task :clone do
26
- if revision?
27
- error "The Git option `:revision` has now been deprecated."
28
- error "Please use `:commit` or `:branch` instead."
29
- exit
30
- end
31
-
32
- clone = if commit?
33
- %[
34
- echo "-----> Using git commit '#{commit}'" &&
35
- #{echo_cmd %[git clone "#{repository!}" . --recursive]} &&
36
- #{echo_cmd %[git checkout -b current_release "#{commit}" --force]} &&
37
- ]
38
- else
39
- %{
40
- if [ ! -d "#{deploy_to}/scm/objects" ]; then
41
- echo "-----> Cloning the Git repository"
42
- #{echo_cmd %[git clone "#{repository!}" "#{deploy_to}/scm" --bare]}
43
- else
44
- echo "-----> Fetching new git commits"
45
- #{echo_cmd %[(cd "#{deploy_to}/scm" && git fetch "#{repository!}" "#{branch}:#{branch}" --force)]}
46
- fi &&
47
- echo "-----> Using git branch '#{branch}'" &&
48
- #{echo_cmd %[git clone "#{deploy_to}/scm" . --recursive --branch "#{branch}"]} &&
49
- }
50
- end
51
-
52
- status = %[
53
- echo "-----> Using this git commit" &&
54
- echo &&
55
- #{echo_cmd %[git rev-parse HEAD > .mina_git_revision]} &&
56
- #{echo_cmd %[git --no-pager log --format='%aN (%h):%n> %s' -n 1]} &&
57
- #{echo_cmd %[rm -rf .git]} &&
58
- echo
59
- ]
60
-
61
- queue clone + status
62
- end
63
-
64
- # ### git:revision
65
- # Gets the current git revision deployed on server.
66
- task :revision do
67
- queue %[cat #{deploy_to}/current/.mina_git_revision]
68
- end
69
- end
data/lib/mina/helpers.rb DELETED
@@ -1,408 +0,0 @@
1
- # # Helpers
2
-
3
- module Mina
4
- module Helpers
5
-
6
- # ### invoke
7
- # Invokes another Rake task.
8
- # By default if the task has already been invoked it will not been executed again (see the `:reenable` option).
9
- #
10
- # Invokes the task given in `task`. Returns nothing.
11
- #
12
- # invoke :'git:clone'
13
- # invoke :restart
14
- #
15
- # Options:
16
- # reenable (bool) - Execute the task even next time.
17
- #
18
-
19
- def invoke(task, options = {})
20
- # task.to_s is a ruby 1.8.7 fix
21
- task = task.to_s
22
- Rake.application.invoke_task task
23
- if options[:reenable]
24
- name = Rake.application.parse_task_string(task).first
25
- Rake::Task[name].reenable
26
- end
27
- end
28
-
29
- # ### erb
30
- # Evaluates an ERB block in the current scope and returns a string.
31
- #
32
- # a = 1
33
- # b = 2
34
- #
35
- # # Assuming foo.erb is <%= a %> and <%= b %>
36
- # puts erb('foo.erb')
37
- #
38
- # #=> "1 and 2"
39
- #
40
- # Returns the output string of the ERB template.
41
-
42
- def erb(file, b=binding)
43
- require 'erb'
44
- erb = ERB.new(File.read(file))
45
- erb.result b
46
- end
47
-
48
- # ### run!
49
- # SSHs into the host and runs the code that has been queued.
50
- #
51
- # This is already automatically invoked before Rake exits to run all
52
- # commands that have been queued up.
53
- #
54
- # queue "sudo restart"
55
- # run!
56
- #
57
- # Returns nothing.
58
-
59
- def run!
60
- report_time { ssh commands(:default) }
61
- end
62
-
63
- # ### run_local!
64
- # runs the code locally that has been queued.
65
- # Has to be in :before_hook or :after_hook queue
66
- #
67
- # This is already automatically invoked before Rake exits to run all
68
- # commands that have been queued up.
69
- #
70
- # to :before_hook do
71
- # queue "cp file1 file2"
72
- # end
73
- # run_local!(:before_hook)
74
- #
75
- # Returns nothing.
76
- def run_local!(aspect)
77
- report_time { local commands(aspect) }
78
- end
79
-
80
- # ### report_time
81
- # Report time elapsed in the block.
82
- # Returns the output of the block.
83
- #
84
- # report_time do
85
- # sleep 2
86
- # # do other things
87
- # end
88
- #
89
- # # Output:
90
- # # Elapsed time: 2.00 seconds
91
-
92
- def report_time(&blk)
93
- time, output = measure &blk
94
- print_str "Elapsed time: %.2f seconds" % [time]
95
- output
96
- end
97
-
98
- # ### measure
99
- # Measures the time (in seconds) a block takes.
100
- # Returns a [time, output] tuple.
101
-
102
- def measure(&blk)
103
- t = Time.now
104
- output = yield
105
- [Time.now - t, output]
106
- end
107
-
108
- # ### mina_cleanup
109
- # __Internal:__ Invoked when Rake exits.
110
- #
111
- # Returns nothing.
112
-
113
- def mina_cleanup!
114
- run_local!(:before_hook) if commands(:before_hook).any?
115
- run! if commands.any?
116
- run_local!(:after_hook) if commands(:after_hook).any?
117
- end
118
-
119
- # ## Errors
120
-
121
- # ### die
122
- # Exits with a nice looking message.
123
- # Returns nothing.
124
- #
125
- # die 2
126
- # die 2, "Tests failed"
127
-
128
- def die(msg=nil, code=1)
129
- str = "Failed with status #{code}"
130
- str += " (#{msg})" if msg
131
- err = Failed.new(str)
132
- err.exitstatus = code
133
- raise err
134
- end
135
-
136
- # ### error
137
- # __Internal:__ Prints to stdout.
138
- # Consider using `print_error` instead.
139
-
140
- def error(str)
141
- $stderr.write "#{str}\n"
142
- end
143
-
144
- # ## Queueing
145
-
146
- # ### queue
147
- # Queues code to be run.
148
- #
149
- # This queues code to be run to the current code bucket (defaults to `:default`).
150
- # To get the things that have been queued, use commands[:default]
151
- #
152
- # Returns nothing.
153
- #
154
- # queue "sudo restart"
155
- # queue "true"
156
- #
157
- # commands == ['sudo restart', 'true']
158
-
159
- def queue(code)
160
- commands
161
- @to ||= :default
162
- commands(@to) << unindent(code)
163
- end
164
-
165
- # ### queue!
166
- # Shortcut for `queue`ing a command that shows up in verbose mode.
167
-
168
- def queue!(code)
169
- queue echo_cmd(code)
170
- end
171
-
172
- # ### echo_cmd
173
- # Converts a bash command to a command that echoes before execution.
174
- # Used to show commands in verbose mode. This does nothing unless verbose mode is on.
175
- #
176
- # Returns a string of the compound bash command, typically in the format of
177
- # `echo xx && xx`. However, if `verbose_mode?` is false, it returns the
178
- # input string unharmed.
179
- #
180
- # echo_cmd("ln -nfs releases/2 current")
181
- # #=> echo "$ ln -nfs releases/2 current" && ln -nfs releases/2 current
182
-
183
- def echo_cmd(str)
184
- if verbose_mode?
185
- require 'shellwords'
186
- "echo #{Shellwords.escape("$ " + str)} &&\n#{str}"
187
- else
188
- str
189
- end
190
- end
191
-
192
- # ## Commands
193
-
194
- # ### commands
195
- # Returns an array of queued code strings.
196
- #
197
- # You may give an optional `aspect`.
198
- #
199
- # Returns an array of strings.
200
- #
201
- # queue "sudo restart"
202
- # queue "true"
203
- #
204
- # to :clean do
205
- # queue "rm"
206
- # end
207
- #
208
- # commands == ["sudo restart", "true"]
209
- # commands(:clean) == ["rm"]
210
-
211
- def commands(aspect = :default)
212
- (@commands ||= begin
213
- Hash.new { |h, k| h[k] = Array.new }
214
- end)[aspect]
215
- end
216
-
217
- # ### isolate
218
- # Starts a new block where new `commands` are collected.
219
- #
220
- # Returns nothing.
221
- #
222
- # queue "sudo restart"
223
- # queue "true"
224
- # commands.should == ['sudo restart', 'true']
225
- #
226
- # isolate do
227
- # queue "reload"
228
- # commands.should == ['reload']
229
- # end
230
- #
231
- # commands.should == ['sudo restart', 'true']
232
-
233
- def isolate(&blk)
234
- old, @commands = @commands, nil
235
- result = yield
236
- new_code, @commands = @commands, old
237
- result
238
- end
239
-
240
- # ### in_directory
241
- # Starts a new block where #commands are collected, to be executed inside `path`.
242
- #
243
- # Returns nothing.
244
- #
245
- # in_directory './webapp' do
246
- # queue "./reload"
247
- # end
248
- #
249
- # commands.should == ['cd ./webapp && (./reload && true)']
250
-
251
- def in_directory(path, &blk)
252
- isolated_commands = isolate { yield; commands }
253
- isolated_commands.each { |cmd| queue "(cd #{path} && (#{cmd}))" }
254
- end
255
-
256
- # ### to
257
- # Defines instructions on how to do a certain thing.
258
- # This makes the commands that are `queue`d go into a different bucket in commands.
259
- #
260
- # Returns nothing.
261
- #
262
- # to :prepare do
263
- # run "bundle install"
264
- # end
265
- # to :launch do
266
- # run "nginx -s restart"
267
- # end
268
- #
269
- # commands(:prepare) == ["bundle install"]
270
- # commands(:restart) == ["nginx -s restart"]
271
-
272
- def to(name, &blk)
273
- old, @to = @to, name
274
- yield
275
- ensure
276
- @to = old
277
- end
278
-
279
- # ## Settings helpers
280
-
281
- # ### set
282
- # Sets settings.
283
- # Sets given symbol `key` to value in `value`.
284
- #
285
- # Returns the value.
286
- #
287
- # set :domain, 'kickflip.me'
288
-
289
- def set(key, value)
290
- settings.send :"#{key}=", value
291
- end
292
-
293
- # ### set_default
294
- # Sets default settings.
295
- # Sets given symbol `key` to value in `value` only if the key isn't set yet.
296
- #
297
- # Returns the value.
298
- #
299
- # set_default :term_mode, :pretty
300
- # set :term_mode, :system
301
- # settings.term_mode.should == :system
302
- #
303
- # set :term_mode, :system
304
- # set_default :term_mode, :pretty
305
- # settings.term_mode.should == :system
306
-
307
- def set_default(key, value)
308
- settings.send :"#{key}=", value unless settings.send(:"#{key}?")
309
- end
310
-
311
- # ### settings
312
- # Accesses the settings hash.
313
- #
314
- # set :domain, 'kickflip.me'
315
- #
316
- # settings.domain #=> 'kickflip.me'
317
- # domain #=> 'kickflip.me'
318
-
319
- def settings
320
- @settings ||= Settings.new
321
- end
322
-
323
- # ### method_missing
324
- # Hook to get settings.
325
- # See #settings for an explanation.
326
- #
327
- # Returns things.
328
-
329
- def method_missing(meth, *args, &blk)
330
- settings.send meth, *args
331
- end
332
-
333
- # ## Command line mode helpers
334
-
335
- # ### verbose_mode?
336
- # Checks if Rake was invoked with --verbose.
337
- #
338
- # Returns true or false.
339
- #
340
- # if verbose_mode?
341
- # queue %[echo "-----> Starting a new process"]
342
- # end
343
-
344
- def verbose_mode?
345
- if Rake.respond_to?(:verbose)
346
- #- Rake 0.9.x
347
- Rake.verbose == true
348
- else
349
- #- Rake 0.8.x
350
- RakeFileUtils.verbose_flag != :default
351
- end
352
- end
353
-
354
- # ### simulate_mode?
355
- # Checks if Rake was invoked with --simulate.
356
- #
357
- # Returns true or false.
358
-
359
- def simulate_mode?
360
- !! ENV['simulate']
361
- end
362
-
363
- # ## Internal helpers
364
-
365
- # ### indent
366
- # Indents a given code block with `count` spaces before it.
367
-
368
- def indent(count, str)
369
- str.gsub(/^/, " "*count)
370
- end
371
-
372
- # ### unindent
373
- # __Internal:__ Normalizes indentation on a given string.
374
- #
375
- # Returns the normalized string without extraneous indentation.
376
- #
377
- # puts unindent %{
378
- # Hello
379
- # There
380
- # }
381
- # # Output:
382
- # # Hello
383
- # # There
384
-
385
- def unindent(code)
386
- if code =~ /^\n([ \t]+)/
387
- code = code.gsub(/^#{$1}/, '')
388
- end
389
-
390
- code.strip
391
- end
392
-
393
- # ### reindent
394
- # Resets the indentation on a given code block.
395
-
396
- def reindent(n, code)
397
- indent n, unindent(code)
398
- end
399
-
400
- # ### capture
401
- # Returns the output of command via SSH.
402
-
403
- def capture(cmd, options={})
404
- ssh cmd, options.merge(:return => true)
405
- end
406
-
407
- end
408
- end