-BEGIN {
- if (-t && $opts{I}) {
- if (eval "require Term::ReadKey; 1") {
- Term::ReadKey->import;
- *policy = sub {
- my ($cmd, $conf, $repo, $status, $signal) = @_;
- return NEXT unless $status;
- print STDERR 'The command failed for ' . $repo->work . "\n";
- print STDERR "[a]bort, [i]gnore, [I]gnore all, [r]etry ?";
- ReadMode(4);
- my $key = ReadKey(0);
- ReadMode(1);
- print STDERR "\n";
- my %codes = (
- 'a' => LAST,
- 'i' => NEXT,
- 'I' => NEXT | SAVE,
- 'r' => REDO,
- );
- $key = 'a' unless defined $key;
- my $code = $codes{$key};
- $code = $codes{a} unless defined $code;
- return $code;
- };
- } else {
- warn "You have to install Term::ReadKey to use the interactive mode.\n";
- }
- }
- *policy = sub { NEXT } if $opts{K} and not defined *policy{CODE};
- *policy = sub {
- my ($cmd, $conf, $repo, $status, $signal) = @_;
- return NEXT unless $status;
- return LAST;
- } unless defined *policy{CODE};
+my $policy;
+
+if (-t && $opts{I}) {
+ $policy = 'Interactive';
+} elsif ($opts{K}) {
+ $policy = 'Keep';
+}
+$policy = eval { App::Rgit::Policy->new(name => $policy) };
+if (not defined $policy) {
+ print STDERR $@ if $@;
+ $policy = App::Rgit::Policy->new(name => 'Default');