Class: MultiCompress::DBDeployment::PackageCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/multi_compress/db_deployment.rb

Constant Summary collapse

TARGETS =
%w[postgres mysql].freeze

Instance Method Summary collapse

Instance Method Details

#run(argv) ⇒ Object

Raises:

  • (OptionParser::MissingArgument)


87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/multi_compress/db_deployment.rb', line 87

def run(argv)
  target = argv.shift
  raise OptionParser::MissingArgument, "TARGET must be postgres or mysql" if target.nil?
  raise OptionParser::InvalidArgument, "TARGET must be postgres or mysql" unless TARGETS.include?(target)

  options = { output: nil, force: false }
  parser = OptionParser.new do |opts|
    opts.banner = "Usage: multi_compress db package #{target} [OPTIONS]"
    opts.on("-o", "--output PATH", "write the deployment archive to PATH") { |value| options[:output] = value }
    opts.on("-f", "--force", "overwrite an existing archive") { options[:force] = true }
    opts.on("-h", "--help", "show this help") { puts opts; return 0 }
  end
  parser.parse!(argv)
  raise OptionParser::InvalidOption, argv.join(" ") unless argv.empty?

  output = options[:output] || "multi_compress-#{target}-#{MultiCompress::VERSION}.tar.gz"
  DeploymentBundle.new(target, output, force: options[:force]).write!
  puts File.expand_path(output)
  0
end