]> git.vpit.fr Git - perl/modules/rgit.git/blobdiff - bin/rgit
Add a diagnostics mode. Only print infos when this mode is enabled
[perl/modules/rgit.git] / bin / rgit
index 326d56edf3f4872485549e7702adc1bfc6ee5446..83bd219a1c0a35558b8fd6a926d0fcbaa6dcdbf1 100755 (executable)
--- a/bin/rgit
+++ b/bin/rgit
@@ -8,7 +8,7 @@ use Config qw/%Config/;
 use Cwd qw/cwd/;
 use File::Spec::Functions qw/catfile path/;
 
-use App::Rgit::Utils qw/:codes/;
+use App::Rgit::Utils qw/:codes :levels/;
 use App::Rgit;
 
 our $VERSION;
@@ -22,10 +22,9 @@ my $cmd;
 BEGIN {
  @ARGV = grep {
   defined $cmd ? $_
-               : ( /^-([IKV]+)$/ ? do { $opts{$_} = 1 for split //, $1; () }
-                                 : do { $cmd = $_ unless /^-/; $_ } )
+               : ( /^-([DIKV]+)$/ ? do { $opts{$_} = 1 for split //, $1; () }
+                                  : do { $cmd = $_ unless /^-/; $_ } )
  } @ARGV;
- warn "rgit $VERSION\n" if $opts{V};
  $cmd = ' ' unless defined $cmd;
 }
 
@@ -68,13 +67,18 @@ croak "Couldn't find any valid git executable" unless defined $git;
 my $root = $ENV{GIT_DIR};
 $root = cwd unless defined $root;
 
-exit App::Rgit->new(
+my $ar = App::Rgit->new(
  git    => $git,
  root   => $root,
  cmd    => $cmd,
  args   => \@ARGV,
  policy => \&policy,
-)->run;
+ debug  => $opts{D} ? INFO : WARN,
+);
+
+print STDOUT "rgit $VERSION\n" if $opts{V};
+
+exit $ar->run;
 
 sub policy_default {
  my ($cmd, $conf, $repo, $status, $signal) = @_;
@@ -95,28 +99,28 @@ sub policy_interactive {
  );
  my $int = { GetControlChars() }->{INTERRUPT};
  while (1) {
-  print STDERR "[a]bort, [i]gnore, [I]gnore all, [r]etry, open [s]hell ?";
+  $conf->warn("[a]bort, [i]gnore, [I]gnore all, [r]etry, open [s]hell ?");
   ReadMode(4);
   my $key = ReadKey(0);
   ReadMode(1);
   print STDERR "\n";
   next unless defined $key;
   if ($key eq $int) {
-   print STDERR "Interrupted, aborting\n";
+   $conf->warn("Interrupted, aborting\n");
    return LAST;
   } elsif ($key eq 's') {
    if (defined $shell) {
-    print STDERR 'Opening shell in ', $repo->work, "\n";
+    $conf->info('Opening shell in ', $repo->work, "\n");
     my $cwd = cwd;
     $repo->chdir;
     system { $shell } $shell;
     chroot $cwd;
    } else {
-    print STDERR "Couldn't find any shell\n";
+    $conf->err("Couldn't find any shell\n");
    }
   } elsif (exists $codes{$key}) {
    my $code = $codes{$key};
-   print STDERR 'Okay, ', $code->[1], "\n";
+   $conf->info('Okay, ', $code->[1], "\n");
    return $code->[0];
   }
  }
@@ -134,7 +138,7 @@ Version 0.04
 
 =head1 SYNOPSIS
 
-    rgit [-K|-V|-I] [GIT_OPTIONS] COMMAND [COMMAND_ARGS]
+    rgit [-K|-I|-D|-V] [GIT_OPTIONS] COMMAND [COMMAND_ARGS]
 
 =head1 DESCRIPTION
 
@@ -211,6 +215,12 @@ This lets you choose interactively what to do when one of the commands returns a
 
 =item *
 
+C<-D>
+
+Outputs diagnostics.
+
+=item *
+
 C<-V>
 
 Outputs the version.