make --local implementation saner
[scpubgit/Tak.git] / lib / Tak / Script.pm
index b7a8f5f..0a4ce6e 100644 (file)
@@ -118,13 +118,12 @@ sub _run_local {
 sub _run_each {
   my ($self, $cmd, $code, @argv) = @_;
   my @targets = $self->_host_list_for($cmd);
-  unless (@targets or $self->options->{local}) {
+  unless (@targets) {
     $self->stderr->print("No targets for ${cmd}\n");
     return;
   }
   my $opt = $self->_maybe_parse_options($code, \@argv);
   $self->local_client->ensure(connector => 'Tak::ConnectorService');
-  $self->$code($self->local_client, $opt, @argv) if $self->options->{local};
   foreach my $target (@targets) {
     my $remote = $self->_connection_to($target);
     $self->$code($remote, $opt, @argv);
@@ -134,20 +133,21 @@ sub _run_each {
 sub _run_every {
   my ($self, $cmd, $code, @argv) = @_;
   my @targets = $self->_host_list_for($cmd);
-  unless (@targets or $self->options->{local}) {
+  unless (@targets) {
     $self->stderr->print("No targets for ${cmd}\n");
     return;
   }
   my $opt = $self->_maybe_parse_options($code, \@argv);
   $self->local_client->ensure(connector => 'Tak::ConnectorService');
   my @remotes = map $self->_connection_to($_), @targets;
-  unshift @remotes, $self->local_client if $self->options->{local};
   $self->$code(\@remotes, $opt, @argv);
 }
 
 sub _host_list_for {
   my ($self, $command) = @_;
   my @host_spec = map split(' ', $_), @{$self->options->{host}};
+  unshift(@host_spec, '-') if $self->options->{local};
+  return @host_spec;
 }
 
 sub _connection_to {