diff --git a/bin/mvcopies b/bin/mvcopies new file mode 100644 index 0000000..5e4a148 --- /dev/null +++ b/bin/mvcopies @@ -0,0 +1,7 @@ +#! /usr/bin/env perl +use strict; +use warnings; +use FindBin; +use lib "$FindBin::Bin/../lib"; +use MVCopies::CLi; +exit MVCopies::CLI->run(\@ARGV); diff --git a/lib/MVCopies/CLI.pm b/lib/MVCopies/CLI.pm new file mode 100644 index 0000000..5fb6f80 --- /dev/null +++ b/lib/MVCopies/CLI.pm @@ -0,0 +1,75 @@ +package MVCopies::CLI + +use strict; +use warnings; +use Getopt::Long qw(GetOptionsFromArray); +use Pod::Usage; +use File::Spec; +use MVCopies::Core; +use MVCopies::Config; + +our $VERSION = '0.01'; + +sub run { + my ($argv_ref) = @_; + my %opts = ( + recursive => 0, + dry_run => 0, + help => 0, + version => 0, + ); + GetOptionsFromArray( + $argv_ref, + 'r|recursive'=>\$opts{recursive}, + 'dry-run'=>\$opts{dry_run}, + 'help|h'=>\$opts{help}, + 'version|v'=>\$opts{version}, + ) or return _usage(); + if ($opts{version}) { + print "mvcopies version: $VERSION\n"; + return 0; + } + if ($opts{help}) { + return _usage(); + } + my $target_dir = shift @$argv_ref; + unless ($target_dir && -d $target_dir) { + warn "Error: Must provide valid directory." + return _usage(); + } + $target_dir = File::Spec->rel2abs($target_dir); + my %core_opts = ( + target_dir => $target_dir, + recursive => $opts{recursive}, + dry_run => $opts{dry_run}, + ); + my $result = MVCopies::Core::run(\%core_opts); + return $result ? 0 : 1; +} +sub _usaage { + pod2usage(-verbose => 1); + return 1; +} +1; + +__END__ + +=head1 NAME + +MVCopies::CLI - Command-line interface for mvcopies + +=head1 SYNOPSIS + + mvcopies [options] + +Options: + + -r, --recursive Scan directories recursively + --dry-run Show what would be moved without moving + -h, --help Show help + -v, --version Show version + +=head1 DESCRIPTION + +This module parses command-line arguments and calls MVCopies::Core +to detect and move duplicate files into a "copies" folder. diff --git a/lib/MVCopies/Config.pm b/lib/MVCopies/Config.pm new file mode 100644 index 0000000..e69de29 diff --git a/lib/MVCopies/Core.pm b/lib/MVCopies/Core.pm new file mode 100644 index 0000000..e69de29 diff --git a/lib/MVCopies/FileOps.pm b/lib/MVCopies/FileOps.pm new file mode 100644 index 0000000..e69de29 diff --git a/mvcopies.pl b/mvcopies.pl old mode 100644 new mode 100755 index 9457aef..d9ed3f5 --- a/mvcopies.pl +++ b/mvcopies.pl @@ -1,4 +1,4 @@ -#! /bin/perl +#!/data/data/com.termux/files/usr/bin/perl use strict; use warnings; use File::Spec;