27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/posgra/cli/grant.rb', line 27
def export(file = nil)
check_fileanem(file)
dsl = client.export_grants
if options[:split]
file = DEFAULT_FILENAME unless file
log(:info, 'Export Grants')
requires = []
dsl.each do |user, content|
user = user.gsub(/\s+/, '_')
user = '_' if user.empty?
grant_file = "#{user}.rb"
requires << grant_file
log(:info, " write `#{grant_file}`")
open(grant_file, 'wb') do |f|
f.puts Posgra::CLI::MAGIC_COMMENT
f.puts content
end
end
log(:info, " write `#{file}`")
open(file, 'wb') do |f|
f.puts Posgra::CLI::MAGIC_COMMENT
requires.each do |grant_file|
f.puts "require '#{File.basename grant_file}'"
end
end
else
if file.nil? or file == '-'
puts dsl
else
log(:info, "Export Grants to `#{file}`")
open(file, 'wb') do |f|
f.puts Posgra::CLI::MAGIC_COMMENT
f.puts dsl
end
end
end
end
|