mirror of
https://git.savannah.gnu.org/git/parallel.git
synced 2024-12-23 05:07:54 +00:00
parallel: Auto add hostgroup if given on arg.
This commit is contained in:
parent
414667b8b4
commit
b843ec7398
54
src/parallel
54
src/parallel
|
@ -1021,7 +1021,7 @@ sub options_hash {
|
|||
"replace|i:s" => \$opt::i,
|
||||
"E=s" => \$opt::eof,
|
||||
"eof|e:s" => \$opt::eof,
|
||||
"max-args|n=i" => \$opt::max_args,
|
||||
"max-args|maxargs|n=i" => \$opt::max_args,
|
||||
"max-replace-args|N=i" => \$opt::max_replace_args,
|
||||
"colsep|col-sep|C=s" => \$opt::colsep,
|
||||
"help|h" => \$opt::help,
|
||||
|
@ -4918,6 +4918,8 @@ sub new {
|
|||
# Look for SSHLogin hostgroups
|
||||
%hostgroups = map { $_ => 1 } split(/\+/, $1);
|
||||
}
|
||||
# An SSHLogin is always in the hostgroup of its "numcpu/host"
|
||||
$hostgroups{$sshlogin_string} = 1;
|
||||
if ($sshlogin_string =~ s:^(\d+)/::) {
|
||||
# Override default autodetected ncpus unless missing
|
||||
$ncpus = $1;
|
||||
|
@ -10302,25 +10304,23 @@ sub get {
|
|||
return $ret;
|
||||
}
|
||||
my $ret = $self->{'arg_sub_queue'}->get();
|
||||
if($ret and
|
||||
grep { index($_->orig(),"\0") > 0 } @$ret) {
|
||||
# Allow for \0 in position 0 because GNU Parallel uses "\0"
|
||||
# to mean no-string
|
||||
::warning("a NUL character occurred in the input.",
|
||||
"It cannot be passed through in the argument list.",
|
||||
"Did you mean to use the --null option?");
|
||||
}
|
||||
if(defined $Global::max_number_of_args
|
||||
and $Global::max_number_of_args == 0) {
|
||||
::debug("run", "Read 1 but return 0 args\n");
|
||||
# \0 => nothing (not the empty string)
|
||||
$ret = [Arg->new("\0")];
|
||||
} else {
|
||||
if($ret) {
|
||||
if(grep { index($_->orig(),"\0") > 0 } @$ret) {
|
||||
# Allow for \0 in position 0 because GNU Parallel uses "\0"
|
||||
# to mean no-string
|
||||
::warning("a NUL character occurred in the input.",
|
||||
"It cannot be passed through in the argument list.",
|
||||
"Did you mean to use the --null option?");
|
||||
}
|
||||
if(defined $Global::max_number_of_args
|
||||
and $Global::max_number_of_args == 0) {
|
||||
::debug("run", "Read 1 but return 0 args\n");
|
||||
# \0 => nothing (not the empty string)
|
||||
map { $_->set_orig("\0"); } @$ret;
|
||||
}
|
||||
# Flush cached computed replacements in Arg-objects
|
||||
# To fix: parallel --bar echo {%} ::: a b c ::: d e f
|
||||
if($ret) {
|
||||
map { $_->flush_cache() } @$ret;
|
||||
}
|
||||
map { $_->flush_cache() } @$ret;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
@ -10703,10 +10703,19 @@ sub new {
|
|||
# We found hostgroups on the arg
|
||||
@hostgroups = split(/\+/, $1);
|
||||
if(not grep { defined $Global::hostgroups{$_} } @hostgroups) {
|
||||
::warning("No such hostgroup (@hostgroups).");
|
||||
@hostgroups = (keys %Global::hostgroups);
|
||||
# This hostgroup is not defined using -S
|
||||
# Add it
|
||||
::warning("Adding hostgroups: @hostgroups");
|
||||
# Add sshlogin
|
||||
for(grep { not defined $Global::hostgroups{$_} } @hostgroups) {
|
||||
my $sshlogin = SSHLogin->new($_);
|
||||
my $sshlogin_string = $sshlogin->string();
|
||||
$Global::host{$sshlogin_string} = $sshlogin;
|
||||
$Global::hostgroups{$sshlogin_string} = 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
# No hostgroup on the arg => any hostgroup
|
||||
@hostgroups = (keys %Global::hostgroups);
|
||||
}
|
||||
}
|
||||
|
@ -10806,6 +10815,11 @@ sub orig {
|
|||
return $self->{'orig'};
|
||||
}
|
||||
|
||||
sub set_orig {
|
||||
my $self = shift;
|
||||
$self->{'orig'} = shift;
|
||||
}
|
||||
|
||||
sub trim_of {
|
||||
# Removes white space as specifed by --trim:
|
||||
# n = nothing
|
||||
|
|
|
@ -91,6 +91,11 @@ par_quoting_for_onall() {
|
|||
echo foo: /bin/ls | parallel --colsep ' ' -S lo --onall ls {2}
|
||||
}
|
||||
|
||||
par_hostgroup_only_on_args() {
|
||||
echo '### Auto add hostgroup if given on on argument'
|
||||
parallel --hostgroup ::: whoami@sh@lo
|
||||
}
|
||||
|
||||
export -f $(compgen -A function | grep par_)
|
||||
# Tested with -j1..8
|
||||
# -j6 was fastest
|
||||
|
|
|
@ -39,6 +39,9 @@ echo '### bug #49404: "Max jobs to run" does not equal the number of jobs specif
|
|||
should give 10 running jobs
|
||||
stdout parallel -S 16/lo --progress true ::: {1..10} | grep /.10
|
||||
1:lo / 16 / 10
|
||||
par_hostgroup_only_on_args ### Auto add hostgroup if given on on argument
|
||||
par_hostgroup_only_on_args parallel: Warning: Adding hostgroups: sh@lo
|
||||
par_hostgroup_only_on_args sh
|
||||
par_quoting_for_onall ### bug #35427: quoting of {2} broken for --onall
|
||||
par_quoting_for_onall /bin/ls
|
||||
par_return_with_fixedstring ### Test --return with fixed string (Gave undef warnings)
|
||||
|
|
Loading…
Reference in a new issue