github.com/dolthub/dolt/go@v0.40.5-0.20240520175717-68db7794bea6/store/cmd/noms/splunk.pl (about)

     1  #!/usr/bin/perl
     2  
     3  my $noms_dir = '.dolt/noms';
     4  
     5  if (! -d $noms_dir) {
     6      die "Use splunk in a dolt directory";
     7  }
     8  
     9  if (! check_exists_command('noms')) {
    10      die "noms binary not found on $PATH";
    11  }   
    12  
    13  print "Welcome to the splunk shell for exploring dolt repository storage.\n";
    14  
    15  my $root = `noms root $noms_dir`;
    16  
    17  my $message = "Currently examining root.\nUse numeric labels to navigate the tree\n.. to back up a level, / to return reload root and return there.\nType quit or exit to exit.\n";
    18  my $hash = $root;
    19  my @stack = ($root);
    20  
    21  while (true) {
    22      my $labels = print_show($hash);
    23  
    24      print $message if $message;
    25      $message = "";
    26      
    27      print "> ";
    28      my $input = <>;
    29      chomp $input;
    30      if ($input eq "quit" or $input eq "exit") {
    31          print "Bye\n";
    32          exit 0;
    33      }
    34  
    35      if ($input eq "..") {
    36          if (scalar @stack <= 1) {
    37              $message = "At top level, cannot go back\n";
    38              next;
    39          }
    40  
    41          shift @stack;
    42          $hash = $stack[0];
    43          next;
    44      }
    45  
    46      if ($input eq "/") {
    47          $root = `noms root $noms_dir`;
    48          $hash = $root;
    49          @stack = ($root);
    50          next;
    51      }
    52  
    53      if (not defined $labels->{$input}) {
    54          $message = "Invalid selection\nChoose a numeric label from the output above, or:\n.. to go back a level, / to go to the root\n";
    55          next;
    56      }
    57  
    58      $hash = $labels->{$input};
    59      unshift @stack, $hash;
    60  }
    61  
    62  sub show {
    63      my $hash = shift;
    64      my $cmd = "noms show $noms_dir\:\:#$hash";
    65      return `$cmd`;
    66  }
    67  
    68  sub get_root {
    69      my $manifest = shift;
    70      for my $line (split /\n/, $manifest) {
    71          next unless $line =~ /root/;
    72          $line =~ /root:\s+([a-z0-9]{32})/;
    73          return $1;
    74      }
    75  
    76      die "couldn't determine root in $manifest";
    77  }
    78  
    79  sub print_show {
    80      my $hash = shift;
    81  
    82      my %hashes;
    83      my $label = 1;
    84      
    85      my $noms_show_output = show($hash);
    86      for my $line (split /\n/, $noms_show_output) {
    87          if ($line =~ /#([a-z0-9]{32})/ ) {
    88              $h = $1;
    89              if ( $1 =~ /[a-z1-9]/ ) {
    90                  $hashes{$label} = $h;
    91                  print "$label)   $line\n";
    92                  $label++;
    93              } else {
    94                  print "     $line\n";
    95              }
    96          } else {
    97              print "     $line\n";
    98          }
    99      }
   100  
   101      return \%hashes;
   102  }
   103  
   104  sub check_exists_command { 
   105      my $check = `sh -c 'command -v $_[0]'`; 
   106      return $check;
   107  }