Class: Tcelfer::CLI::DBTasks

Inherits:
Thor
  • Object
show all
Defined in:
lib/tcelfer/cli/db_tasks.rb

Overview

Subcommands for various database tasks

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*_args) ⇒ DBTasks

Returns a new instance of DBTasks.



21
22
23
24
25
26
# File 'lib/tcelfer/cli/db_tasks.rb', line 21

def initialize(*_args)
  # Quit on Ctrl-C please
  @prompt = TTY::Prompt.new(interrupt: :exit)

  super
end

Class Method Details

.exit_on_failure?Boolean

Useful return codes are nice, of course

Returns:

  • (Boolean)


29
30
31
# File 'lib/tcelfer/cli/db_tasks.rb', line 29

def self.exit_on_failure?
  true
end

Instance Method Details

#initdbObject



39
40
41
42
43
44
45
46
# File 'lib/tcelfer/cli/db_tasks.rb', line 39

def initdb
  Tcelfer.config.debug = options[:verbose]
  _db_exists! if File.exist?(Tcelfer.config.sqlite_path) && !options.force

  _db_migrate!
rescue Tcelfer::Error => e
  @prompt.error("[#{e.class}]", e)
end

#migrateObject



50
51
52
53
54
55
# File 'lib/tcelfer/cli/db_tasks.rb', line 50

def migrate
  Tcelfer.config.debug = options[:verbose]
  _db_migrate!(options.version)
rescue Tcelfer::Error => e
  @prompt.error("[#{e.class}]", e)
end

#pathObject



58
59
60
# File 'lib/tcelfer/cli/db_tasks.rb', line 58

def path
  @prompt.say(Tcelfer.config.sqlite_path)
end