]> git.ktnx.net Git - mpd-feeder.git/blobdiff - bin/mpd-feeder
set autoflush on stderr so that logging to systemd's journal (via UNIX socket) is...
[mpd-feeder.git] / bin / mpd-feeder
index 79d0b1b858926841cbad61586a35231bfb4017f3..29a6d5b10f6247f2bf6e9ee54e65ae96f8e16605 100755 (executable)
@@ -2,72 +2,25 @@
 
 use strict;
 use warnings;
-use utf8;
+use utf8::all;
 
 use App::MPD::Feeder;
-use App::MPD::Feeder::Options;
 use Log::Any qw($log);
 use Log::Any::Adapter Stderr => log_level => 'error';
 
-my $feeder = Feeder->new();
-
-if (@ARGV) {
-    my $cmd = shift @ARGV;
-
-    if ($cmd eq 'dump-config') {
-        die "dump-config command accepts no arguments\n" if @ARGV;
-
-        $feeder->opt->dump;
-        exit;
-    }
-
-    if ( $cmd eq 'add-unwanted-artist' ) {
-        die "Missing command arguments\n" unless @ARGV;
-        $feeder->set_db_needs_update(0);
-        for my $artist (@ARGV) {
-            if ( $feeder->db_add_unwanted_artist($artist) ) {
-                $log->info("Artist '$artist' added to the unwanted list\n");
-            }
-            else {
-                $log->warn("Artist '$artist' already in the unwanted list\n");
-            }
-        }
-        exit;
-    }
-
-    if ( $cmd eq 'del-unwanted-artist' ) {
-        die "Missing command arguments\n" unless @ARGV;
-        $feeder->set_db_needs_update(0);
-        for my $artist (@ARGV) {
-            if ( $feeder->db_del_unwanted_artist($artist) ) {
-                $log->info("Artist '$artist' deleted from the unwanted list\n");
-            }
-            else {
-                $log->warn("Artist '$artist' is not in the unwanted list\n");
-            }
-        }
-        exit;
-    }
-
-    if ( $cmd eq 'add-unwanted-album' ) {
-        die "NOT IMPLEMENTED\n";
-    }
+{   # autoflush without IO::Handle
+    my $fh = select STDERR;
+    $| = 1;
+    select $fh;
+}
 
-    if ( $cmd eq 'one-shot' ) {
-        die "one-shot command accepts no arguments\n" if @ARGV;
+my $feeder = App::MPD::Feeder->new();
 
-        $feeder->queue_songs(undef, sub { exit });
-        $feeder->mpd->loop->run;
-    }
-    elsif ( $cmd eq 'single' ) {
-        die "single command accepts no arguments\n" if @ARGV;
+if (@ARGV) {
+    require App::MPD::Feeder::Command;
+    bless $feeder, 'App::MPD::Feeder::Command';
 
-        $feeder->queue_songs(1, sub { exit });
-        $feeder->mpd->loop->run;
-    }
-    else {
-        die "Unknown command '$cmd'";
-    }
+    exit $feeder->run(@ARGV);
 }
 
 $feeder->run_loop;