Class: KamalBackup::CLI

Inherits:
Thor
  • Object
show all
Includes:
Helpers
Defined in:
lib/kamal_backup/cli.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, #bridge, #command_env, #confirm!, #deploy_snippet, #deployment_mode?, #direct_app, #exec_remote, #init_config_root, #local_app, #local_command_config, #local_preferences, #prompt_required, #redactor, #shared_config_path, #shared_config_template, #write_init_file

Class Attribute Details

.command_envObject

Returns the value of attribute command_env.



229
230
231
# File 'lib/kamal_backup/cli.rb', line 229

def command_env
  @command_env
end

Class Method Details

.basenameObject



267
268
269
# File 'lib/kamal_backup/cli.rb', line 267

def self.basename
  "kamal-backup"
end

.normalize_global_options(argv) ⇒ Object



231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/kamal_backup/cli.rb', line 231

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



271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/kamal_backup/cli.rb', line 271

def self.start(argv = ARGV, env: ENV)
  self.command_env = env
  super(normalize_global_options(argv))
rescue Error => e
  warn("kamal-backup: #{Redactor.new(env: env).redact_string(e.message)}")
  exit(1)
rescue Interrupt
  warn("kamal-backup: interrupted")
  exit(130)
ensure
  self.command_env = nil
end

Instance Method Details

#backupObject



287
288
289
290
291
292
293
# File 'lib/kamal_backup/cli.rb', line 287

def backup
  if deployment_mode?
    exec_remote(["kamal-backup", "backup"])
  else
    direct_app.backup
  end
end

#checkObject



305
306
307
308
309
310
311
# File 'lib/kamal_backup/cli.rb', line 305

def check
  if deployment_mode?
    exec_remote(["kamal-backup", "check"])
  else
    puts(direct_app.check)
  end
end

#evidenceObject



314
315
316
317
318
319
320
# File 'lib/kamal_backup/cli.rb', line 314

def evidence
  if deployment_mode?
    exec_remote(["kamal-backup", "evidence"])
  else
    puts(direct_app.evidence)
  end
end

#initObject



323
324
325
326
327
328
329
330
331
332
333
# File 'lib/kamal_backup/cli.rb', line 323

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 "For most Rails apps, restore local and drill local can infer the development database, storage path, and tmp state directory."
  puts "Create config/kamal-backup.local.yml only if you need to override those local defaults."
end

#listObject



296
297
298
299
300
301
302
# File 'lib/kamal_backup/cli.rb', line 296

def list
  if deployment_mode?
    exec_remote(["kamal-backup", "list"])
  else
    puts(direct_app.snapshots)
  end
end

#scheduleObject



336
337
338
339
340
341
342
# File 'lib/kamal_backup/cli.rb', line 336

def schedule
  if deployment_mode?
    exec_remote(["kamal-backup", "schedule"])
  else
    direct_app.schedule
  end
end

#versionObject



345
346
347
348
349
350
351
# File 'lib/kamal_backup/cli.rb', line 345

def version
  if deployment_mode?
    exec_remote(["kamal-backup", "version"])
  else
    puts(VERSION)
  end
end