#!/usr/bin/env ruby require 'optparse' require 'ostruct' require 'cli_spinnable' require 'pg_export' require 'pg_export/includable_modules/colourable_string' require 'pg_export/includable_modules/interactive' config = PgExport::ServicesContainer.config pg_export = PgExport.new option_parser = OptionParser.new do |opts| opts.banner = 'Usage: pg_export [options]' opts.on('-d', '--database DATABASE', '[Required] Name of the database to export') do |database| config.database = database end opts.on('-k', '--keep [KEEP]', Integer, "[Optional] Number of dump files to keep on FTP (default: #{config.keep_dumps})") do |keep| config.keep_dumps = keep end opts.on('-t', '--timestamped', '[Optional] Enables log messages with timestamps') do PgExport::Logging.format_timestamped end opts.on('-i', '--interactive', 'Interactive, command line mode, for restoring dumps into databases') do PgExport::Logging.mute config.database ||= 'undefined' pg_export.extend(PgExport::Interactive) end opts.on('-h', '--help', 'Show this message') do puts opts exit end opts.separator "\nSetting can be verified by running following commands:" opts.on('-c', '--configuration', 'Prints the configuration') do puts config.to_s exit end opts.on('-f', '--ftp', 'Tries connecting to FTP to verify the connection') do PgExport::ServicesContainer.ftp_connection.open exit end end begin option_parser.parse! pg_export.call rescue OptionParser::MissingArgument, PgExport::InvalidConfigurationError => e using PgExport::ColourableString puts "Error: #{e}".red puts option_parser rescue PgExport::PgDumpError => e puts e end