#!/usr/bin/env perl

use strict;
use warnings;

use MYDan::Node;
use MYDan::Util::MIO::CMD;
use MYDan::Util::OptConf;
use MYDan::VSSH::Print;

$| ++;

$MYDan::Util::OptConf::ARGC = -1;
@MYDan::Util::OptConf::CONF = qw( pass_through );

=head1 SYNOPSIS

 $0 -r range [--noop] [--verbose] cmd ..

    [--timeout seconds (default 300) ]
    [--max number (default 128) ]
    [--interchange (default {})]
    [--xx]

  echo "input" |$0 -r range cmd

=cut
my $option = MYDan::Util::OptConf->load();
my %o = $option->get( qw( range=s timeout=i max=i interchange=s noop verbose xx ) )->dump();

$option->assert( 'range' );

my $range = MYDan::Node->new( $option->dump( 'range' ) );
my %cmd = map { $_ => \@ARGV } $range->load( delete $o{range} )->list();

my ( %result, %re ) = MYDan::Util::MIO::CMD->new( %cmd )->run( %o );

while( my ( $type, $result ) = each %result )
{
    map{ my $t = $_; map{ $re{$_} .= $t } @{$result->{$t}};}keys %$result;
}

MYDan::VSSH::Print::result( 'mcmd' => %re );
