Class: Hooray::CLI
- Inherits:
-
Thor
show all
- Defined in:
- lib/hooray/cli.rb
Overview
Instance Method Summary
collapse
Constructor Details
#initialize(*args) ⇒ CLI
Returns a new instance of CLI.
9
10
11
12
13
14
|
# File 'lib/hooray/cli.rb', line 9
def initialize(*args)
super
return if ARGV.first =~ /init/
Settings.load!
@start = Time.now
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*params) ⇒ Object
124
125
126
127
128
129
130
131
132
133
134
135
136
|
# File 'lib/hooray/cli.rb', line 124
def method_missing(*params)
case params.size
when 1 then
puts "Do you want to `#{params.first}` to a device?"
puts "Use #{ARGV.first} #{params.first} <device name>"
when 2 then
command, name = params
device = Hooray::Seek.new.devices.find { |d| d.name == name }
return puts("Could not find '#{name}'") unless device
system "#{command} #{device.ip}"
else super
end
end
|
Instance Method Details
#init ⇒ Object
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/hooray/cli.rb', line 22
def init
return if Dir.exist?(Settings::CONFIG_DIR)
pa 'Creating ~/.hooray directory', :red
Dir.mkdir(Settings::CONFIG_DIR)
settings_dir = File.join(File.dirname(__FILE__), 'settings')
%w(settings.yml devices.yml services.yml nmap-mac-prefixes).each do |file|
pa "Creating ~/.hooray/#{file}", :red
FileUtils.cp "#{settings_dir}/#{file}", Settings::CONFIG_DIR
end
end
|
#list(*filter) ⇒ Object
39
40
41
42
43
44
45
46
47
|
# File 'lib/hooray/cli.rb', line 39
def list(*filter)
puts sweep = Seek.new(options[:network], *filter)
if sweep.nodes.empty?
pa "No results for filter #{filter.join(' ')}", :red
else
print_table(sweep.nodes)
end
puts
end
|
#local ⇒ Object
88
89
90
|
# File 'lib/hooray/cli.rb', line 88
def local
Kernel.system 'LANG=en netstat -na | grep "tcp.*LISTEN"'
end
|
#update ⇒ Object
79
80
|
# File 'lib/hooray/cli.rb', line 79
def update
end
|
#watch ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/hooray/cli.rb', line 60
def watch
print_table old_seek = Seek.new(options[:network]).nodes
pa 'Starting watch...', :red
loop do
sleep 5
new_seek = Seek.new(options[:network]).nodes
print_change :new, (new_seek - old_seek)
print_change :old, (old_seek - new_seek), :red
old_seek = new_seek
end
end
|