]> git.nbdom.net Git - nb.git/commitdiff
accept args
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 25 Aug 2016 21:26:35 +0000 (22:26 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 25 Aug 2016 21:26:35 +0000 (22:26 +0100)
bin/nb-repo-dirs

index 25e89565980c0c3602bb099c643b42987a49b53b..cc13dbfce573b07cacbc68c42f915322021a8a9d 100755 (executable)
@@ -8,6 +8,11 @@ use strict;
 use File::Spec;
 use Cwd;
 use File::Basename;
+my $FILE_EXISTS = '.nb-install';
+
+my $debug = 0;
+($ARGV[0]||'') =~ /^--?(all|debug)$/ and $debug = 1 and shift @ARGV;
+
 my @DIRS = (
        dirname ( dirname ( File::Spec->rel2abs( Cwd::abs_path(__FILE__) ) ) ),
        '/opt/backup_servers',
@@ -19,38 +24,44 @@ my @DIRS = (
 #      '/home/www/*/.nb-install',
 #      '/home/*/Dev/*/.nb-install',
 #      '/usr/local/src/*/.nb-install',
-       '/{opt,opt/www,home,home/www,usr/local/src,home/*/Dev,home/share/git}/*/.nb-install',
+       "/{opt,opt/www,home,home/www,usr/local/src,home/*/Dev,home/share/git}/*/$FILE_EXISTS",
 );
 
-my $debug = 0;
-($ARGV[0]||'') =~ /^--?(all|debug)$/ and $debug = 1;
-if ($ARGV[0]||'' =~ /^--?(all|debug)$/) {
-  print map {"$_\n"} @DIRS;
-  exit 0;
-}
 
-my %h;
+#print map {"$_\n"} add_args(@DIRS) and exit 0 if $debug;
 
+my %h;
 print
        map {"$_\n"}
        grep {$_ ne "" and !$h{$_}++}
        map {
 
-# TODEL user - NB 17.01.16
-               my $user = (s/^(\w+:)// ? $1 : "");
-               my $dir = /\.nb-install$/ ? dirname($_) : $_;
-
-               if ($debug) {
-                       $user.$dir;
-
-               } elsif (-d $dir and -d "$dir/.git") {
-                       $user.$dir;
+    # To reduce glob return, we permit to use file
+               #my $dir = /\/\Q$FILE_EXISTS\E$/ ? dirname($_) : $_;
+               my $dir = !-d  $_ ? dirname($_) : $_;
 
+               if (-d $dir and -d "$dir/.git") {
+      warn "DEBUG: MISSING: $dir\n" if $debug and !-r "$dir/FILE_EXISTS";
+      add_args($dir);
+                       #$dir;
                } else {
+      warn "DEBUG: REJECT : $dir\n" if $debug;
                        "";
-
                }
 
        }
        glob join(' ',@DIRS)
 ;
+
+sub add_args {
+  # Concat each args (ex: $0 proie etc/profile ...)
+  my @new;
+  foreach my $d (@_) {
+    foreach my $a (@ARGV) {
+      #warn "$d/$a";
+      push @new, "$d/$a";
+    }
+  }
+  return @new if @new;
+  return @_;
+}