Skip to content

Instantly share code, notes, and snippets.

Created February 4, 2017 23:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4cd6a3aae0097dc8712534eb9bbe5640 to your computer and use it in GitHub Desktop.
Save anonymous/4cd6a3aae0097dc8712534eb9bbe5640 to your computer and use it in GitHub Desktop.
# Constants
my $script = basename($0);
my $version = '0.1';
# Handle arguments
my $dbfile = "$ENV{HOME}/.config/banshee-1/banshee.db";
my $export_dir;
my $library_root;
my $msg = q[Dump all of banshee's playlists (Banshee Playlist Export)];
@ARGV or pod2usage(-message => $msg, -exitval => 0, -verbose => 0 );
GetOptions('help' => sub { &pod2usage(-message => $msg,
-exitval => 0 ) },
'h' => sub { &pod2usage(-message => $msg,
-exitval => 0,
-verbose => 0 ) },
'man' => sub { &pod2usage(-exitval => 0,
-verbose => 2 ) },
'version|V' => sub { print "$script $version\n"; exit(0) },
'dbfile=s' => \$dbfile,
'export-dir|e=s' => \$export_dir,
'library-root|l=s' => \$library_root
) or die("Try `$script --help' for more information.\n");
die("$script: missing required argument --export-dir\n")
unless defined $export_dir;
die("$script: export directory does not exist.\n")
unless -e $export_dir;
die("$script: banshee database does not exist or is not readable\n")
unless (-f $dbfile && -r $dbfile);
$library_root = $export_dir
unless defined $library_root;
========================================
# Constants
constant script = $?FILE.IO.basename;
constant version = '0.1';
# Not implemented yet
#sub USAGE{
# q[Dump all of banshee's playlists (Banshee Playlist Export)].say;
# $?USAGE.say;
#}
multi MAIN( Bool:D :h(:$help) ) is hidden-from-USAGE {
say "Print help here.";
exit(0)
}
multi MAIN( Bool:D :V(:$version)) is hidden-from-USAGE {
say "{script} {version}";
exit(0)
}
multi MAIN( Str :e(:$export_dir)! where
{ .IO.d // die "{script}: export directory does not exist." },
Str :l(:$library_root) where
{ .IO.d // die "{script}: export directory does not exist." }
= $export_dir,
Str :$dbfile where
{ .IO.f && .IO.r // die "{script}: banshee database does not "
~ " exist or is not readable" }
= "%*ENV<HOME>/.config/banshee-1/banshee.db"
)
{
exit 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment