diff options
| -rw-r--r-- | vcx | 53 |
1 files changed, 36 insertions, 17 deletions
@@ -4,30 +4,49 @@ use strict; use warnings; use File::Path qw(make_path); +use constant VCX_DIR => '.vcx'; +use constant BASE_DIR => VCX_DIR . '/bse'; +use constant OBJ_DIR => VCX_DIR . '/obj'; +use constant TMP_DIR => VCX_DIR . '/tmp'; + my $cmd = $ARGV[0] // ''; if ($cmd eq 'init') { - init_repo(); + init_repo(); +} elsif ($cmd eq 'status') { + run_status(); } else { - print "Usage: $0 [command]\n"; - exit 1; + print "Usage: $0 [init|status]\n"; + exit 1; } sub init_repo { - my @dirs = ( - '.vcx/obj', - '.vcx/bse', - '.vcx/tmp' - ); - - foreach my $dir (@dirs) { - if (!-d $dir) { - make_path($dir); - print "Created: $dir\n"; - } - } - - print "Repository ready\n"; + my @dirs = (OBJ_DIR, BASE_DIR, TMP_DIR); + foreach my $dir (@dirs) { + if (!-d $dir) { + make_path($dir); + print "Created: $dir\n"; + } + } + print "Repository ready\n"; } +sub run_status { + my $diff_cmd = "diff -x " . VCX_DIR . " -rq " . BASE_DIR . " ."; + $diff_cmd .= " -X .vcxignore" if -e ".vcxignore"; + + my @output = `$diff_cmd`; + + foreach my $line (@output) { + chomp $line; + # Format output + if ($line =~ /^Only in \Q@{[BASE_DIR]}\E: (.+)$/) { + print "[D] $1\n"; + } elsif ($line =~ /^Only in \.: (.+)$/) { + print "[N] $1\n"; + } elsif ($line =~ /^Files \Q@{[BASE_DIR]}\E\/(.+) and \.\/(.+) differ$/) { + print "[M] $1\n"; + } + } +} |
