Class: SecureDBFields::DBDeployment::PackageCommand

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

Instance Method Summary collapse

Instance Method Details

#run(argv) ⇒ Object

Raises:

  • (OptionParser::MissingArgument)


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/secure_db_fields/db_deployment.rb', line 70

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

  options = { output: nil, force: false }
  parser = OptionParser.new do |opts|
    opts.banner = "Usage: secure_db_fields db package mysql [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] || "secure_db_fields-mysql-#{SecureDBFields::VERSION}.tar.gz"
  DeploymentBundle.new(output, force: options[:force]).write!
  puts File.expand_path(output)
  0
end