Class: Hotdog::Commands::Hosts
- Inherits:
-
BaseCommand
- Object
- BaseCommand
- Hotdog::Commands::Hosts
- Defined in:
- lib/hotdog/commands/hosts.rb
Direct Known Subclasses
Constant Summary
Constants inherited from BaseCommand
Instance Attribute Summary
Attributes inherited from BaseCommand
#application, #logger, #options
Instance Method Summary collapse
Methods inherited from BaseCommand
#execute, #fixed_string?, #initialize
Constructor Details
This class inherits a constructor from Hotdog::Commands::BaseCommand
Instance Method Details
#run(args = []) ⇒ Object
6 7 8 9 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 |
# File 'lib/hotdog/commands/hosts.rb', line 6 def run(args=[]) args = optparse.parse(args) if args.empty? result = execute("SELECT DISTINCT host_id FROM hosts_tags").to_a.reduce(:+) else result = args.map { |host_name| if glob?(host_name) execute(<<-EOS, host_name).map { |row| row.first } SELECT DISTINCT hosts_tags.host_id FROM hosts_tags INNER JOIN hosts ON hosts_tags.host_id = hosts.id WHERE LOWER(hosts.name) GLOB LOWER(?); EOS else execute(<<-EOS, host_name).map { |row| row.first } SELECT DISTINCT hosts_tags.host_id FROM hosts_tags INNER JOIN hosts ON hosts_tags.host_id = hosts.id WHERE LOWER(hosts.name) = LOWER(?); EOS end }.reduce(:+) end if 0 < result.length result, fields = get_hosts(result) STDOUT.print(format(result, fields: fields)) logger.info("found %d host(s)." % result.length) else STDERR.puts("no match found: #{args.join(" ")}") exit(1) end end |