lib/dexter/client.rb in pgdexter-0.1.6 vs lib/dexter/client.rb in pgdexter-0.2.0
- old
+ new
@@ -10,24 +10,25 @@
STDOUT.sync = true
STDERR.sync = true
if options[:statement]
query = Query.new(options[:statement])
- Indexer.new(arguments[0], options).process_queries([query])
+ Indexer.new(options).process_queries([query])
elsif options[:pg_stat_statements]
- Indexer.new(arguments[0], options).process_stat_statements
- elsif arguments[1]
- Processor.new(arguments[0], arguments[1], options).perform
+ Indexer.new(options).process_stat_statements
+ elsif arguments.any?
+ ARGV.replace(arguments)
+ Processor.new(ARGF, options).perform
else
- Processor.new(arguments[0], STDIN, options).perform
+ Processor.new(STDIN, options).perform
end
end
def parse_args(args)
opts = Slop.parse(args) do |o|
o.banner = %(Usage:
- dexter <database-url> [options]
+ dexter [options]
Options:)
o.boolean "--create", "create indexes", default: false
o.array "--exclude", "prevent specific tables from being indexed"
o.string "--include", "only include specific tables"
@@ -36,31 +37,35 @@
o.boolean "--pg-stat-statements", "use pg_stat_statements", default: false, help: false
o.boolean "--log-explain", "log explain", default: false, help: false
o.string "--log-level", "log level", default: "info"
o.boolean "--log-sql", "log sql", default: false
o.string "-s", "--statement", "process a single statement"
+ o.separator ""
+ o.separator "Connection options:"
o.on "-v", "--version", "print the version" do
log Dexter::VERSION
exit
end
- o.on "-h", "--help", "prints help" do
+ o.on "--help", "prints help" do
log o
exit
end
+ o.string "-U", "--username"
+ o.string "-d", "--dbname"
+ o.string "-h", "--host"
+ o.integer "-p", "--port"
end
arguments = opts.arguments
+ options = opts.to_hash
- if arguments.empty?
- log opts
- exit
- end
+ options[:dbname] = arguments.shift unless options[:dbname]
- abort "Too many arguments" if arguments.size > 2
+ # TODO don't use global var
+ $log_level = options[:log_level].to_s.downcase
+ abort "Unknown log level" unless ["error", "info", "debug", "debug2"].include?($log_level)
- abort "Unknown log level" unless ["info", "debug", "debug2"].include?(opts.to_hash[:log_level].to_s.downcase)
-
- [arguments, opts.to_hash]
+ [arguments, options]
rescue Slop::Error => e
abort e.message
end
def log(message)