#!/usr/bin/env perl
use strict;
use warnings;

use YAML::XS;
use MYDan::Util::OptConf;
use MYDan::Util::WhoIs;

$| ++;

$MYDan::Util::OptConf::ARGC = 1;

=head1 SYNOPSIS

 $0 hostname.abc
 $0 10.10.10.10  
 $0 /abc       #search abc from db

=cut

my $option = MYDan::Util::OptConf->load()->get()->dump();
my $whois = MYDan::Util::WhoIs->new();

my $name = shift @ARGV;
my %whois = $name =~ s/^\/// ? $whois->search( $name ) : $whois->whois( $name );

my ( $c, $h ) = @whois{qw( cluster hosts )};

print "\ncluster:\n";
print "No match.\n" unless @$c;
map{ print } sort map{ sprintf "%s\n", join "\t", @$_;}@$c;

print "\nhosts:\n";
print "No match.\n" unless %$h;
map{ print }sort map{sprintf "$_\t$h->{$_}\n", }keys %$h;
