lib/spanx/cli/flush.rb in spanx-0.1.1 vs lib/spanx/cli/flush.rb in spanx-0.3.0

- old
+ new

@@ -1,12 +1,25 @@ require 'mixlib/cli' require 'spanx/logger' class Spanx::CLI::Flush < Spanx::CLI - banner "Usage: spanx flush [options]" + banner 'Usage: spanx flush [ -a | -i IPADDRESS ] [options]' + description 'Remove a specific IP block, or all blocked IPs' + option :ip, + :short => '-i IPADDRESS', + :long => '--ip IPADDRESS', + :description => 'Unblock specific IP', + :required => false + + option :all, + :short => '-a', + :long => '--all', + :description => 'Unblock all IPs', + :required => false + option :config_file, :short => '-c CONFIG', :long => '--config CONFIG', :description => 'Path to config file (YML)', :required => true @@ -29,8 +42,20 @@ :exit => 0 def run(argv = ARGV) generate_config(argv) - Spanx::IPChecker.unblock_all + out = '' + keys = if config[:ip] =~ /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/ + out << "unblocking ip #{config[:ip]}: " + Spanx::IPChecker.new(config[:ip]).unblock + elsif config[:all] + out << 'unblocking all IPs: ' if config[:debug] + Spanx::IPChecker.unblock_all + else + error_exit_with_msg 'Either -i or -a flag is required now' + end + out << "deleted #{keys} IPs that matched" + puts out if config[:debug] + out end end