Explicitly require 'common/errors' in RmRunner.
[mailshears.git] / lib / rm / rm_runner.rb
1 require 'common/errors'
2 require 'common/runner'
3
4 class RmRunner
5 include Runner
6
7 def run(plugin, *targets)
8 targets.each do |target|
9 # Why think too hard? An user has an @, a domain doesn't.
10 if target.include?('@') then
11 begin
12 user_description = plugin.describe_user(target)
13 plugin.delete_user(target)
14 report(plugin, "Removed user: #{target} (#{user_description})")
15
16 rescue NonexistentUserError => e
17 report(plugin, "User not found: #{e.to_s}")
18 rescue StandardError => e
19 report(plugin, "There was an error removing the user: #{e.to_s}")
20 Kernel.exit(ExitCodes::DATABASE_ERROR)
21 end
22 else
23 begin
24 domain_description = plugin.describe_domain(target)
25 plugin.delete_domain(target)
26 report(plugin, "Removed domain: #{target} (#{domain_description})")
27
28 rescue NonexistentUserError => e
29 # Can happen in the usernames.each... block.
30 report(plugin, "User not found: #{e.to_s}")
31 rescue NonexistentDomainError => e
32 report(plugin, "Domain not found: #{e.to_s}")
33 rescue StandardError => e
34 report(plugin, "There was an error removing the domain: #{e.to_s}")
35 Kernel.exit(ExitCodes::DATABASE_ERROR)
36 end
37 end
38 end
39
40 end
41
42 end