mirror: Introduce two functions for running commands

They are thin wrappers over `system`, but two main points:

 * They log the (unescaped) command.
 * `run` will auto-die.

This removes the need to pepper `== 0 or die` in the script.
This commit is contained in:
Samuel Dionne-Riel 2020-03-24 15:24:51 -04:00
parent f4d04077c6
commit ab952e5863

View file

@ -15,6 +15,27 @@ use List::MoreUtils qw(uniq);
use Net::Amazon::S3;
use POSIX qw(strftime);
# Runs the given command, printing the (unescaped) command.
# This command continues on failure.
sub runAllowFailure {
print STDERR " \$ ", join(" ", @_), "\n";
system(@_);
}
# Runs the given command, printing the (unescaped) command.
# This command dies on failure.
sub run {
my $context = caller(0);
my $code = runAllowFailure(@_);
unless ($code == 0) {
my $exit = $code >> 8;
my $errno = $code - ($exit << 8);
die "Command failed with code ($exit) errno ($errno).\n";
}
return $code;
}
my $channelName = $ARGV[0];
my $releaseUrl = $ARGV[1];