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
BaseCommand::MASK_DATABASE, BaseCommand::MASK_QUERY, BaseCommand::PERSISTENT_DB
Instance Attribute Summary
Attributes inherited from BaseCommand
#application, #logger, #options
Instance Method Summary collapse
Methods inherited from BaseCommand
#execute, #fixed_string?, #initialize, #reload
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 |
# File 'lib/hotdog/commands/hosts.rb', line 6 def run(args=[]) args = optparse.parse(args) if args.empty? result = execute("SELECT id FROM hosts").to_a.reduce(:+) else result = args.flat_map { |host_name| if glob?(host_name) execute("SELECT id FROM hosts WHERE name GLOB ?", [host_name]).to_a.reduce(:+) else execute("SELECT id FROM hosts WHERE name = ?", [host_name]).to_a.reduce(:+) end } end if result && (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 |