Class: KamalBackup::CLI
- Inherits:
-
Thor
- Object
- Thor
- KamalBackup::CLI
show all
- Includes:
- Helpers
- Defined in:
- lib/kamal_backup/cli.rb,
lib/kamal_backup/cli/helpers.rb
Defined Under Namespace
Modules: Helpers
Classes: CommandBase, DrillCLI, RestoreCLI
Class Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Helpers
#accessory_name, #accessory_reboot_command, #bridge, #command_env, #confirm!, #confirm_production_restore!, #default_deploy_config?, #deploy_snippet, #deployment_mode?, #direct_app, #ensure_remote_version_match!, #exec_remote, #init_config_root, #local_command_config, #local_preferences, #local_restore_app, #print_backup_result, #print_prune_result, #print_remote_version_status, #production_restore_confirmation_config, #production_source_defaults, #prompt_required, #redactor, #remote_command_mode?, #remote_version, #require_typed_confirmation, #shared_config_path, #shared_config_source_defaults, #shared_config_template, #validate_deploy_config, #write_init_file
Class Attribute Details
.command_env ⇒ Object
Returns the value of attribute command_env.
103
104
105
|
# File 'lib/kamal_backup/cli.rb', line 103
def command_env
@command_env
end
|
Class Method Details
.basename ⇒ Object
141
142
143
|
# File 'lib/kamal_backup/cli.rb', line 141
def self.basename
'kamal-backup'
end
|
.normalize_global_options(argv) ⇒ Object
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/kamal_backup/cli.rb', line 105
def normalize_global_options(argv)
tokens = Array(argv).dup
leading = []
while tokens.any?
token = tokens.first
case token
when '-d', '--destination', '-c', '--config-file'
leading << tokens.shift
leading << tokens.shift if tokens.any?
when /\A--destination=.+\z/, /\A--config-file=.+\z/
leading << tokens.shift
else
break
end
end
if leading.empty? || tokens.empty?
Array(argv)
else
[tokens.shift, *leading, *tokens]
end
end
|
.start(argv = ARGV, env: ENV) ⇒ Object
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
# File 'lib/kamal_backup/cli.rb', line 145
def self.start(argv = ARGV, env: ENV)
self.command_env = env
output = CommandOutput.new(io: $stderr, env: env)
Command.with_output(output) do
super(normalize_global_options(argv))
end
rescue StandardError => e
output.error("(#{e.class}): #{e.message}", redactor: Redactor.new(env: env))
exit(1)
rescue Interrupt
output.error('(Interrupt): interrupted', redactor: Redactor.new(env: env))
exit(130)
ensure
self.command_env = nil
end
|
Instance Method Details
#backup ⇒ Object
166
167
168
169
170
171
172
173
174
|
# File 'lib/kamal_backup/cli.rb', line 166
def backup
if remote_command_mode?
argv = %w[kamal-backup backup]
argv << '--force' if options[:force]
exec_remote(argv)
else
print_backup_result(direct_app.backup(force: options[:force]))
end
end
|
#check ⇒ Object
186
187
188
189
190
191
192
|
# File 'lib/kamal_backup/cli.rb', line 186
def check
if remote_command_mode?
exec_remote(%w[kamal-backup check])
else
puts(direct_app.check)
end
end
|
#evidence ⇒ Object
213
214
215
216
217
218
219
|
# File 'lib/kamal_backup/cli.rb', line 213
def evidence
if remote_command_mode?
exec_remote(%w[kamal-backup evidence])
else
puts(direct_app.evidence)
end
end
|
#init ⇒ Object
233
234
235
236
237
238
239
240
241
242
243
244
245
246
|
# File 'lib/kamal_backup/cli.rb', line 233
def init
write_init_file(shared_config_path, shared_config_template)
puts
puts 'Add this accessory block to your Kamal deploy config:'
puts
puts deploy_snippet
puts
puts 'The accessory runs scheduled database and configured file backups with backup.schedule.'
puts 'File backups run only for paths explicitly configured in config/kamal-backup.yml.'
puts 'Rails local restores infer the development database and tmp state directory, but never file paths.'
puts 'Local restore and drill also require the restic binary on your machine.'
puts 'When production paths are configured, set their local targets in config/kamal-backup.local.yml.'
end
|
#list ⇒ Object
177
178
179
180
181
182
183
|
# File 'lib/kamal_backup/cli.rb', line 177
def list
if remote_command_mode?
exec_remote(%w[kamal-backup list])
else
puts(direct_app.snapshots)
end
end
|
#prune ⇒ Object
204
205
206
207
208
209
210
|
# File 'lib/kamal_backup/cli.rb', line 204
def prune
if remote_command_mode?
exec_remote(%w[kamal-backup prune])
else
print_prune_result(direct_app.prune)
end
end
|
#schedule ⇒ Object
249
250
251
252
253
254
255
|
# File 'lib/kamal_backup/cli.rb', line 249
def schedule
if deployment_mode?
exec_remote(%w[kamal-backup schedule])
else
direct_app.schedule
end
end
|
#unlock ⇒ Object
195
196
197
198
199
200
201
|
# File 'lib/kamal_backup/cli.rb', line 195
def unlock
if remote_command_mode?
exec_remote(%w[kamal-backup unlock])
else
print(direct_app.unlock)
end
end
|
#validate ⇒ Object
222
223
224
225
226
227
228
229
230
|
# File 'lib/kamal_backup/cli.rb', line 222
def validate
if remote_command_mode?
validate_deploy_config
else
direct_app.validate
end
puts('ok')
end
|
#version ⇒ Object
258
259
260
261
262
263
264
|
# File 'lib/kamal_backup/cli.rb', line 258
def version
if remote_command_mode?
print_remote_version_status
else
puts(VERSION)
end
end
|