class Debloater::CLI
Constants
- DEFAULTS
Public Class Methods
new(argv)
click to toggle source
# File lib/debloater/cli.rb, line 24 def initialize(argv) @options = _parse(argv.dup) end
Public Instance Methods
run()
click to toggle source
# File lib/debloater/cli.rb, line 28 def run conn = Connection.new(@options[:connection]) Engine.new(conn, @options[:engine]).run end
Private Instance Methods
_parse(argv)
click to toggle source
# File lib/debloater/cli.rb, line 35 def _parse(argv) options = DEFAULTS.dup parser = OptionParser.new do |opts| opts.banner = "Usage: debloater [options] database" opts.on('-h HOST', 'Database host to connect to [localhost]') do |v| options[:connection][:host] = v end opts.on('-p PORT', 'Port to connect to [5432]') do |v| options[:connection][:port] = v end opts.on('-U USER', 'Username to connect with [postgres]') do |v| options[:connection][:user] = v end opts.on('-W', 'Prompt for password (default)') do options[:prompt_password] = true end opts.on('-w', 'No prompt for password') do options[:prompt_password] = false end opts.on('--auto', 'Do not ask for confirmation before debloating') do |v| options[:engine][:confirm] = false end opts.on('--min-mb [SIZE]', 'Do not debloat if the bloat size is lower than SIZE megabytes [50]') do |v| options[:engine][:min_mb] = v.to_f end opts.on('--max-density [FRACTION]', 'Do not debloat if the index density is higher than FRACTION [0.75]') do |v| options[:engine][:min_mb] = v.to_f end opts.on('--help', 'Prints this help') do puts opts exit end end parser.parse!(argv) case argv.length when 1 then options[:connection][:dbname] = argv.pop else puts parser exit 1 end if options[:prompt_password] options[:connection][:password] = IO.console.getpass('Enter password (no echo):') end options end