Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.

Commit

Permalink
Add --target-user option
Browse files Browse the repository at this point in the history
  • Loading branch information
Genki Sugawara committed Oct 8, 2014
1 parent 49bcfe0 commit 5f63b74
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
36 changes: 18 additions & 18 deletions bin/gratan
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ options = {

ARGV.options do |opt|
begin
opt.on('' , '--host HOST') {|v| mysql_options[:host] = v }
opt.on('' , '--port PORT', Integer) {|v| mysql_options[:port] = v }
opt.on('' , '--socket SOCKET') {|v| mysql_options[:socket] = v }
opt.on('' , '--username USERNAME') {|v| mysql_options[:username] = v }
opt.on('' , '--password PASSWORD') {|v| mysql_options[:password] = v }
opt.on('' , '--database DATABASE') {|v| mysql_options[:database] = v }
opt.on('-a', '--apply') { mode = :apply }
opt.on('-f', '--file FILE') {|v| file = v }
opt.on('' , '--dry-run') { options[:dry_run] = true }
opt.on('-e', '--export') { mode = :export }
opt.on('' , '--with-identifier') { options[:with_identifier] = true }
opt.on('' , '--enable-expired') { options[:enable_expired] = true }
opt.on('' , '--split') { split = true }
opt.on('-o', '--output FILE') {|v| output_file = v }
opt.on('' , '--ignore-user REGEXP') {|v| options[:ignore_user] = Regexp.new(v) }
opt.on('' , '--no-color') { options[:color] = false }
opt.on('' , '--debug') { options[:debug] = true }

opt.on('' , '--host HOST') {|v| mysql_options[:host] = v }
opt.on('' , '--port PORT', Integer) {|v| mysql_options[:port] = v }
opt.on('' , '--socket SOCKET') {|v| mysql_options[:socket] = v }
opt.on('' , '--username USERNAME') {|v| mysql_options[:username] = v }
opt.on('' , '--password PASSWORD') {|v| mysql_options[:password] = v }
opt.on('' , '--database DATABASE') {|v| mysql_options[:database] = v }
opt.on('-a', '--apply') { mode = :apply }
opt.on('-f', '--file FILE') {|v| file = v }
opt.on('' , '--dry-run') { options[:dry_run] = true }
opt.on('-e', '--export') { mode = :export }
opt.on('' , '--with-identifier') { options[:with_identifier] = true }
opt.on('' , '--enable-expired') { options[:enable_expired] = true }
opt.on('' , '--split') { split = true }
opt.on('-o', '--output FILE') {|v| output_file = v }
opt.on('' , '--ignore-user REGEXP') {|v| options[:ignore_user] = Regexp.new(v) }
opt.on('' , '--target-user REGEXP') {|v| options[:target_user] = Regexp.new(v) }
opt.on('' , '--no-color') { options[:color] = false }
opt.on('' , '--debug') { options[:debug] = true }
opt.on('' , '--auto-identify OUTPUT') {|v| options[:identifier] = Gratan::Identifier::Auto.new(v, options) }
opt.on('' , '--csv-identify CSV') {|v| options[:identifier] = Gratan::Identifier::CSV.new(v, options) }

Expand Down
10 changes: 10 additions & 0 deletions lib/gratan/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ def walk(file, options)

expected.each do |user_host, expected_attrs|
next if user_host[0] =~ options[:ignore_user]

if options[:target_user]
next unless user_host[0] =~ options[:target_user]
end

actual_attrs = actual.delete(user_host)

if actual_attrs
Expand All @@ -54,6 +59,11 @@ def walk(file, options)

actual.each do |user_host, attrs|
next if user_host[0] =~ options[:ignore_user]

if options[:target_user]
next unless user_host[0] =~ options[:target_user]
end

drop_user(*user_host)
end
end
Expand Down

0 comments on commit 5f63b74

Please sign in to comment.