Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a simple shell for exploring a noms dataset #1905

Merged
merged 1 commit into from Jul 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
103 changes: 103 additions & 0 deletions go/store/cmd/noms/splunk.pl
@@ -0,0 +1,103 @@
#!/usr/bin/perl

my $noms_dir = '.dolt/noms';

if (! -d $noms_dir) {
die "Use splunk in a dolt directory";
}

if (! check_exists_command('noms')) {
die "noms binary not found on $PATH";
}

print "Welcome to the splunk shell for exploring dolt repository storage.\n";

my $manifest = `noms manifest $noms_dir`;
my $root = get_root($manifest);

my $message = "Currently examining root.\nUse numeric labels to navigate the tree\n.. to back up a level, / to return to root.\nType quit or exit to exit.\n";

my $hash = $root;
my @stack = ($root);

while (true) {
my $labels = print_show($hash);

print $message if $message;
$message = "";

print "> ";
my $input = <>;
chomp $input;
if ($input eq "quit" or $input eq "exit") {
print "Bye\n";
exit 0;
}

if ($input eq "..") {
if (scalar @stack <= 1) {
$message = "At top level, cannot go back\n";
next;
}

shift @stack;
$hash = $stack[0];
next;
}

if ($input eq "/") {
$hash = $root;
@stack = ($root);
next;
}

if (not defined $labels->{$input}) {
$message = "Invalid selection\nChoose a numeric label from the output above, or:\n.. to go back a level, / to go to the root\n";
next;
}

$hash = $labels->{$input};
unshift @stack, $hash;
}

sub show {
my $hash = shift;
my $cmd = "noms show $noms_dir\:\:#$hash";
return `$cmd`;
}

sub get_root {
my $manifest = shift;
for my $line (split /\n/, $manifest) {
next unless $line =~ /root/;
$line =~ /root:\s+([a-z0-9]{32})/;
return $1;
}

die "couldn't determine root in $manifest";
}

sub print_show {
my $hash = shift;

my %hashes;
my $label = 1;

my $noms_show_output = show($hash);
for my $line (split /\n/, $noms_show_output) {
if ($line =~ /#([a-z0-9]{32})/) {
$hashes{$label} = $1;
print "$label) $line\n";
$label++;
} else {
print " $line\n";
}
}

return \%hashes;
}

sub check_exists_command {
my $check = `sh -c 'command -v $_[0]'`;
return $check;
}