Module: Posgra::CLI::Helper

Included in:
Database, Grant, Role
Defined in:
lib/posgra/cli/helper.rb

Constant Summary collapse

REGEXP_OPTIONS =
[
  :include_schema,
  :exclude_schema,
  :include_role,
  :exclude_role,
  :include_object,
  :exclude_object,
]

Instance Method Summary collapse

Instance Method Details

#check_fileanem(file) ⇒ Object



11
12
13
14
15
# File 'lib/posgra/cli/helper.rb', line 11

def check_fileanem(file)
  if file =~ /\A-.+/
    raise "Invalid failname: #{file}"
  end
end

#clientObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/posgra/cli/helper.rb', line 17

def client
  client_options = {}
  String.colorize = options[:color]
  Posgra::Logger.instance.set_debug(options[:debug])

  options.each do |key, value|
    if key.to_s =~ /-/
      key = key.to_s.gsub('-', '_')
    end

    client_options[key.to_sym] = value if value
  end

  REGEXP_OPTIONS.each do |key|
    if client_options[key]
      client_options[key] = Regexp.new(client_options[key])
    end
  end

  client_options[:identifier] = Posgra::Identifier::Auto.new(options['account-output'], client_options)
  Posgra::Client.new(client_options)
end