Class: Blitz::Command::Traceroute
- Inherits:
-
Blitz::Command
- Object
- Blitz::Command
- Blitz::Command::Traceroute
- Defined in:
- lib/blitz/command/traceroute.rb
Overview
:nodoc:
Constant Summary
Constants inherited from Blitz::Command
Instance Method Summary collapse
- #cmd_default(argv) ⇒ Object
- #cmd_help(argv) ⇒ Object
- #print_result(args, result, last_index) ⇒ Object
Methods included from Utils
Methods included from Helper
Instance Method Details
#cmd_default(argv) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/blitz/command/traceroute.rb', line 10 def cmd_default argv args = parse_cli argv continue = true last_index = nil begin [ 'INT', 'STOP', 'HUP' ].each do |s| trap(s) { continue = false } end job = ::Blitz::Traceroute.queue args msg "running from #{yellow(job.region)}..." puts job.result do |result| print_result args, result, last_index if not result.hops.empty? last_index = result.hops.size end sleep 2.0 if not continue continue end puts msg "[#{red('aborted')}]" if not continue rescue ::Blitz::Traceroute::Error::Region => e error "#{yellow(e.region)}: #{red(e.)}" rescue ::Blitz::Traceroute::Error => e error red(e.) end end |
#cmd_help(argv) ⇒ Object
4 5 6 7 8 |
# File 'lib/blitz/command/traceroute.rb', line 4 def cmd_help argv puts msg "Usage: blitz traceroute [-r <region>] host" puts end |
#print_result(args, result, last_index) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/blitz/command/traceroute.rb', line 40 def print_result args, result, last_index if last_index and result.hops.size == last_index return end result.hops[(last_index || 0)..result.hops.size].each do |hop| if hop =~ /!/ puts red(hop) elsif hop =~ /\*/ puts yellow(hop) else puts hop end end end |